| Newsgroups |
perl.cvs.perlfaq |
| Message-ID |
<[email protected]> |
cvsuser 02/06/20 21:37:21
Modified: . perlfaq6.pod
Log:
* How can I match strings with multibyte characters?
+ added an example from Benjamin Goldberg who used
negative lookbehind to make a slightly less painful
way to do it.
Revision Changes Path
1.14 +14 -6 perlfaq/perlfaq6.pod
Index: perlfaq6.pod
===================================================================
RCS file: /cvs/public/perlfaq/perlfaq6.pod,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -r1.13 -r1.14
--- perlfaq6.pod 17 Jun 2002 04:44:13 -0000 1.13
+++ perlfaq6.pod 21 Jun 2002 04:37:21 -0000 1.14
@@ -1,6 +1,6 @@
=head1 NAME
-perlfaq6 - Regular Expressions ($Revision: 1.13 $, $Date: 2002/06/17 04:44:13 $)
+perlfaq6 - Regular Expressions ($Revision: 1.14 $, $Date: 2002/06/21 04:37:21 $)
=head1 DESCRIPTION
@@ -694,13 +694,21 @@
print "found GX!\n", last if $1 eq 'GX';
}
-Or like this:
+Here's another, slightly less painful, way to do it from Benjamin
+Goldberg:
- die "sorry, Perl doesn't (yet) have Martian support )-:\n";
+ $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]).
-There are many double- (and multi-) byte encodings commonly used these
-days. Some versions of these have 1-, 2-, 3-, and 4-byte characters,
-all mixed.
+It does have the drawback of putting the wrong thing in $-[0] and $+[0],
+but this usually can be worked around.
=head2 How do I match a pattern that is supplied by the user?