X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlrequick.pod;h=a31adab5eb8f4a7372c7dd70960c7b0e4d134c29;hb=55e8fca7cffebeb1d95d86b8d8a21177c004c656;hp=a14229c303ddd4e30bb74a798bb9d63422f6a1df;hpb=4b19af017623bfa3bb72bb164598a517f586e0d3;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlrequick.pod b/pod/perlrequick.pod index a14229c..a31adab 100644 --- a/pod/perlrequick.pod +++ b/pod/perlrequick.pod @@ -166,24 +166,31 @@ Perl has several abbreviations for common character classes: =over 4 =item * + \d is a digit and represents [0-9] =item * + \s is a whitespace character and represents [\ \t\r\n\f] =item * + \w is a word character (alphanumeric or _) and represents [0-9a-zA-Z_] =item * + \D is a negated \d; it represents any character but a digit [^0-9] =item * + \S is a negated \s; it represents any non-whitespace character [^\s] =item * + \W is a negated \w; it represents any non-word character [^\w] =item * + The period '.' matches any character but "\n" =back @@ -212,11 +219,11 @@ boundary. =head2 Matching this or that -We can match match different character strings with the B +We can match different character strings with the B metacharacter C<'|'>. To match C or C, we form the regex C. As before, perl will try to match the regex at the earliest possible point in the string. At each character position, -perl will first try to match the the first alternative, C. If +perl will first try to match the first alternative, C. If C doesn't match, perl will then try the next alternative, C. If C doesn't match either, then the match fails and perl moves to the next position in the string. Some examples: @@ -231,7 +238,7 @@ C is able to match earlier in the string. "cats" =~ /cats|cat|ca|c/; # matches "cats" At a given character position, the first alternative that allows the -regex match to succeed wil be the one that matches. Here, all the +regex match to succeed will be the one that matches. Here, all the alternatives match at the first string position, so th first matches. =head2 Grouping things and hierarchical matching @@ -297,18 +304,30 @@ have the following meanings: =over 4 -=item * C = match 'a' 1 or 0 times +=item * -=item * C = match 'a' 0 or more times, i.e., any number of times +C = match 'a' 1 or 0 times + +=item * -=item * C = match 'a' 1 or more times, i.e., at least once +C = match 'a' 0 or more times, i.e., any number of times -=item * C = match at least C times, but not more than C +=item * + +C = match 'a' 1 or more times, i.e., at least once + +=item * + +C = match at least C times, but not more than C times. -=item * C = match at least C or more times +=item * + +C = match at least C or more times + +=item * -=item * C = match exactly C times +C = match exactly C times =back