From a3cb178b0bad32fa8be934503d051b96a3cb1fea Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Thu, 14 May 1998 07:00:02 +0000 Subject: [win32] merge changes#872,873 from maintbranch p4raw-link: @873 on //depot/maint-5.004/perl: 990f469d529b62458be38e8659885fd26d353629 p4raw-link: @872 on //depot/maint-5.004/perl: 0b85608df162729d39cb0f96c9f88c7de0a3ceab p4raw-id: //depot/win32/perl@935 --- pod/perlre.pod | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'pod/perlre.pod') diff --git a/pod/perlre.pod b/pod/perlre.pod index 373e1ca84e..e985377586 100644 --- a/pod/perlre.pod +++ b/pod/perlre.pod @@ -278,16 +278,16 @@ matches a word followed by a tab, without including the tab in C<$&>. A zero-width negative lookahead assertion. For example C matches any occurrence of "foo" that isn't followed by "bar". Note however that lookahead and lookbehind are NOT the same thing. You cannot -use this for lookbehind: C will not find an occurrence of -"bar" that is preceded by something which is not "foo". That's because +use this for lookbehind. If you are looking for a "bar" which isn't preceeded +"foo", C will not do what you want. That's because the C<(?!foo)> is just saying that the next thing cannot be "foo"--and it's not, it's a "bar", so "foobar" will match. You would have to do something like C for that. We say "like" because there's the case of your "bar" not having three characters before it. You could -cover that this way: C. Sometimes it's still +cover that this way: C. Sometimes it's still easier just to say: - if (/foo/ && $` =~ /bar$/) + if (/bar/ && $` !~ /foo$/) For lookbehind see below. @@ -653,9 +653,18 @@ first alternative includes everything from the last pattern delimiter the last alternative contains everything from the last "|" to the next pattern delimiter. For this reason, it's common practice to include alternatives in parentheses, to minimize confusion about where they -start and end. Note however that "|" is interpreted as a literal with -square brackets, so if you write C<[fee|fie|foe]> you're really only -matching C<[feio|]>. +start and end. + +Note that alternatives are tried from left to right, so the first +alternative found for which the entire expression matches, is the one that +is chosen. This means that alternatives are not necessarily greedy. For +example: when mathing C against "barefoot", only the "foo" +part will match, as that is the first alternative tried, and it successfully +matches the target string. (This might not seem important, but it is +important when you are capturing matched text using parentheses.) + +Also note that "|" is interpreted as a literal within square brackets, +so if you write C<[fee|fie|foe]> you're really only matching C<[feio|]>. Within a pattern, you may designate subpatterns for later reference by enclosing them in parentheses, and you may refer back to the Ith -- cgit v1.2.1 From 9b599b2a63d2324ddacddd9710c41b795a95070d Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Thu, 14 May 1998 09:31:34 +0000 Subject: [win32] merge change#887 from maintbranch p4raw-link: @887 on //depot/maint-5.004/perl: 6cdf74fe31f049dc2164dbb9e6242179d4b8ee1f p4raw-id: //depot/win32/perl@937 --- pod/perlre.pod | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'pod/perlre.pod') diff --git a/pod/perlre.pod b/pod/perlre.pod index e985377586..95da75d95f 100644 --- a/pod/perlre.pod +++ b/pod/perlre.pod @@ -704,4 +704,10 @@ different things on the I side of the C. =head2 SEE ALSO +L. + +L. + +L. + "Mastering Regular Expressions" (see L) by Jeffrey Friedl. -- cgit v1.2.1 From 7b8d334a971230040a212bc5038097b3f600a094 Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Thu, 14 May 1998 23:11:05 +0000 Subject: [win32] merge change#897 from maintbranch p4raw-link: @897 on //depot/maint-5.004/perl: f06f9b6fc5a686f0169ee2a91b32d5e7125a44ae p4raw-id: //depot/win32/perl@974 --- pod/perlre.pod | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'pod/perlre.pod') diff --git a/pod/perlre.pod b/pod/perlre.pod index 95da75d95f..f029cbecc1 100644 --- a/pod/perlre.pod +++ b/pod/perlre.pod @@ -34,6 +34,13 @@ line anywhere within the string, Treat string as single line. That is, change "." to match any character whatsoever, even a newline, which it normally would not match. +The /s and /m modifiers both override the C<$*> setting. That is, no matter +what C<$*> contains, /s (without /m) will force "^" to match only at the +beginning of the string and "$" to match only at the end (or just before a +newline at the end) of the string. Together, as /ms, they let the "." match +any character whatsoever, while yet allowing "^" and "$" to match, +respectively, just after and just before newlines within the string. + =item x Extend your pattern's legibility by permitting whitespace and comments. @@ -139,7 +146,7 @@ also work: \Q quote (disable) regexp metacharacters till \E If C is in effect, the case map used by C<\l>, C<\L>, C<\u> -and <\U> is taken from the current locale. See L. +and C<\U> is taken from the current locale. See L. In addition, Perl defines the following: @@ -238,7 +245,7 @@ non-alphanumeric characters: $pattern =~ s/(\W)/\\$1/g; Now it is much more common to see either the quotemeta() function or -the \Q escape sequence used to disable the metacharacters special +the C<\Q> escape sequence used to disable all metacharacters' special meanings like this: /$unquoted\Q$quoted\E$unquoted/ @@ -278,14 +285,15 @@ matches a word followed by a tab, without including the tab in C<$&>. A zero-width negative lookahead assertion. For example C matches any occurrence of "foo" that isn't followed by "bar". Note however that lookahead and lookbehind are NOT the same thing. You cannot -use this for lookbehind. If you are looking for a "bar" which isn't preceeded -"foo", C will not do what you want. That's because -the C<(?!foo)> is just saying that the next thing cannot be "foo"--and -it's not, it's a "bar", so "foobar" will match. You would have to do -something like C for that. We say "like" because there's -the case of your "bar" not having three characters before it. You could -cover that this way: C. Sometimes it's still -easier just to say: +use this for lookbehind. + +If you are looking for a "bar" which isn't preceded by a "foo", C +will not do what you want. That's because the C<(?!foo)> is just saying that +the next thing cannot be "foo"--and it's not, it's a "bar", so "foobar" will +match. You would have to do something like C for that. We +say "like" because there's the case of your "bar" not having three characters +before it. You could cover that this way: C. +Sometimes it's still easier just to say: if (/bar/ && $` !~ /foo$/) -- cgit v1.2.1 From 48c036b1eb8f866b948f33704ee6152323a5aad9 Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Fri, 15 May 1998 01:34:53 +0000 Subject: [win32] merge change#905 from maintbranch, minor fixes to get clean build+test on Solaris p4raw-link: @905 on //depot/maint-5.004/perl: 15e73149a8419f18d739227762eab108524cec56 p4raw-id: //depot/win32/perl@976 --- pod/perlre.pod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pod/perlre.pod') diff --git a/pod/perlre.pod b/pod/perlre.pod index f029cbecc1..68ce4b9bf7 100644 --- a/pod/perlre.pod +++ b/pod/perlre.pod @@ -395,7 +395,7 @@ Say, matches a chunk of non-parentheses, possibly included in parentheses themselves. -=item C<(?imsx)> +=item C<(?imstx)> One or more embedded pattern-match modifiers. This is particularly useful for patterns that are specified in a table somewhere, some of -- cgit v1.2.1