Seriously Todd? "What is a digit?" The characters '0' to '9' are digits.
(Unicode probably has a whole lot of others, but those will do for the moment.)
On Mon, 11 Dec 2023, at 18:22, ToddAndMargo via perl6-users wrote:
> On 12/10/23 22:26, William Michels via perl6-users wrote:
> If I do not know the length of the sting and have to ask
> with .chars, is there a way to use a variable in `** 7`
>
> ** $x.chars or
> my $xlen = $x.chars; `** $xlen`
>
> or some such? Is there a special syntax?
>
> Also, must the `**7` (does it have a name?) always be the length
> of the string?
>
> Also, if I do not use ^ and $, what happens?
These are really basic questions.
"**7" is a modifier. It means that the previous item must match exactly 7
times. Just like "+" means "one or more" and "*" means "zero or more". The "7"
can be a range. Thus "<[0..9]>**1..7" means one to seven digits.
To interpolate code into a regex, use the { raku code } syntax. Perhaps
"**{$x.chars}" will work. (I'm not sure of that one.) On the other hand, if you
just want to make sure that everything is a digit, "/ ^ <[0..9]>+ $ /" will
work fine. Or even simpler "/ ^ \d+ $ /" since "\d" just means "a digit"
(although you will also get anything else Unicode considers a digit).
If you do not include the '^' and/or '$' characters, then the match may occur
in the middle (or start or end) of a longer string.