summaryrefslogtreecommitdiff
path: root/pod/perlfaq6.pod
diff options
context:
space:
mode:
Diffstat (limited to 'pod/perlfaq6.pod')
-rw-r--r--pod/perlfaq6.pod24
1 files changed, 12 insertions, 12 deletions
diff --git a/pod/perlfaq6.pod b/pod/perlfaq6.pod
index 168233bd1b..d19ba36bf8 100644
--- a/pod/perlfaq6.pod
+++ b/pod/perlfaq6.pod
@@ -1,6 +1,6 @@
=head1 NAME
-perlfaq6 - Regular Expressions ($Revision: 1.20 $, $Date: 2003/01/03 20:05:28 $)
+perlfaq6 - Regular Expressions ($Revision: 1.26 $, $Date: 2004/10/25 18:47:04 $)
=head1 DESCRIPTION
@@ -354,7 +354,7 @@ created by Jeffrey Friedl and later modified by Fred Curtis.
$/ = undef;
$_ = <>;
- s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs
+ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse;
print;
This could, of course, be more legibly written with the C</x> modifier, adding
@@ -395,11 +395,11 @@ whitespace and comments. Here it is expanded, courtesy of Fred Curtis.
. ## Anything other char
[^/"'\\]* ## Chars which doesn't start a comment, string or escape
)
- }{$2}gxs;
+ }{defined $2 ? $2 : ""}gxse;
A slight modification also removes C++ comments:
- s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs;
+ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse;
=head2 Can I use Perl regular expressions to match balanced text?
@@ -745,17 +745,17 @@ Or like this:
}
Here's another, slightly less painful, way to do it from Benjamin
-Goldberg:
+Goldberg, who uses a zero-width negative look-behind assertion.
- $martian =~ m/
- (?!<[A-Z])
- (?:[A-Z][A-Z])*?
- GX
- /x;
+ print "found GX!\n" if $martian =~ m/
+ (?<![A-Z])
+ (?:[A-Z][A-Z])*?
+ GX
+ /x;
This succeeds if the "martian" character GX is in the string, and fails
-otherwise. If you don't like using (?!<), you can replace (?!<[A-Z])
-with (?:^|[^A-Z]).
+otherwise. If you don't like using (?<!), a zero-width negative
+look-behind assertion, you can replace (?<![A-Z]) with (?:^|[^A-Z]).
It does have the drawback of putting the wrong thing in $-[0] and $+[0],
but this usually can be worked around.