This is from my keeper on "match".  It is the Perl 5 way
of explaining things.  It works really well for me.

How did I do?



To find a match of "any" of the following

my $x="abc2def"; say so $x.match( / ^ <+[0..9] + [a..z]> ** 7 $ / )
my $x="abc2def"; say so $x.match( / ^ <+[0..9] + [a..z]> ** {$x.chars} $ / )
True

Explanation of the above:
   This is the "match" usage of "regex".

   The test starts from the beginning of the string and ends
   at the end of the string.  It asks each cell in the string
   if contains one of characters taken from the set of
   characters including the digits "0"-through-"9" and
   the lowercase letters "a"-through-"z".

      $x is the string to test

      `so` removed the individual results of each cell in $x and
      just return a single True or False

      `.match()` is the test command (method) applied by the regex
      to $x.  The `()` is required.  And you have to spell out ".match"

       The `/` at the beginning and end are the constraints of
       the regex.   Note that there are only two of them, not three
       as with a substitution regex (~~s/xx/y/)

      `^` means to start testing at the beginning of $x

      `<[0..9]> + [a..z]>` are the range of alpha numeric characters
      (not numbers) to test for in each $x cell.  In this case, the
      the lowercase letters "a"-through-"z" and the digits "0"-through-"9".
      (Note: string character that look like numbers and not binary
      number, but ASCII repersention of numbers)

      `** 8` and ** `{$x.chars}` are the length of $x.  If you "goof"
      the length of $x (larger or smaller), regex will return a Nil.
      `{$x.chars}` will avoid this.

      `$` means to stop testing at the end of $x


Reply via email to