[Mastering-perl] 02.advanced_regular_expressions
David H. Adler
dha at panix.com
Fri Dec 22 01:32:57 EST 2006
Another diff
--
David H. Adler - <dha at panix.com> - http://www.panix.com/~dha/
"If it's not Jewish, it's CRAP!:)" - IsraelBeta on #DWC
-------------- next part --------------
--- 02.advanced_regular_expressions.pod 2006-12-17 20:52:48.000000000 -0500
+++ 02.advanced_regular_expressions.pod.rev 2006-12-22 01:30:37.000000000 -0500
@@ -260,7 +260,7 @@
\s*$
/x
-Under X</x>, to match whitespace I have to specify it explicitly,
+Under C</x>, to match whitespace I have to specify it explicitly,
either using C<\s>, which matches any whitespace, any of C<\f\r\n\t>,
or their octal or hexadecimal sequences, such as \040 or \x20 for a
literal spaceN<I can also escape a literal space character with a
@@ -341,7 +341,7 @@
I modify that snippet to use the C</i> flag to turn on
case-insensitivity:
- my $regex = qr/(\S+) hacker/;
+ my $regex = qr/(\S+) hacker/i;
print "$regex\n";
The output now shows me that case-insensitivity is on, but the other
@@ -411,8 +411,8 @@
Perl6 comes after Perl 5.
I just say "Perl".
This is a Perl 5 line
- Perl5 is the current version.
- Just another Perl5 hacker,
+ Perl 5 is the current version.
+ Just another Perl 5 hacker,
At the end is Perl
The regular expression will not match these lines because "Perl" shows
@@ -463,7 +463,7 @@
lookaheads, because the assertions, once they match, won't backtrack
or try something else if a later part of the regular expression fails.
-To demonstrate that, I use a string with five <a>'s followed by a
+To demonstrate that, I use a string with five C<a>'s followed by a
C<b>. My positive lookahead assertion matches C<ab>. Although it
doesn't consume any characters, it anchors the match position to right
after its match, which is right after the first C<ab>. The rest of the
@@ -580,7 +580,7 @@
my $word_count = () = /(\S+)/g;
-This uses a little-known rule but important rule: the result of a list
+This uses a little-known but important rule: the result of a list
assignment is the number of elements in the list on the right-hand
side. In this case, that's the number of elements the match operator
returns. This only works for a list assignment, which is assigning
@@ -611,7 +611,7 @@
I can even look at the match position as I go along. The built-in
C<pos()> operator returns the match position for the string I give it
-(or C<$_> by default). Every string maintains it own position. The
+(or C<$_> by default). Every string maintains its own position. The
first position in the string is C<0>, so C<pos()> returns C<undef> when
it doesn't find a match and has been reset. This only works when I'm
using the C</g> flag:
@@ -746,9 +746,9 @@
my( $type, $found );
next unless $line =~ /$regex/gc;
- last LOOP if $1 eq "\n";
print "Found a $description [$1]\n";
+ last LOOP if $1 eq "\n";
next LOOP;
}
@@ -796,7 +796,7 @@
Second, it tries to match the target string, and shows its progress
through the nodes.
- $ perl -Dr examine-regex 'Just another Perl hacker,' 'Just another (\S+) hacker,'
+ $ perl -Dr explain-regex 'Just another Perl hacker,' 'Just another (\S+) hacker,'
Omitting $` $& $' support.
EXECUTING...
@@ -982,7 +982,7 @@
The F<perlre> is the main documentation for Perl regular expressions, and
F<perlretut> give a regular expression tutorial. Don't confuse that with
-F<perlreftut>, the tutorial on references. Too make it even more complicated,
+F<perlreftut>, the tutorial on references. To make it even more complicated,
C<perlreref> is the regular expression quick reference.
The details for regular expression debugging shows up in F<perldebguts>. It
More information about the Mastering-perl
mailing list