Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Using regex to match double letters, and only double letters

by davido (Cardinal)
on Dec 30, 2005 at 05:05 UTC ( #519948=note: print w/replies, xml ) Need Help??


in reply to Using regex to match double letters, and only double letters

I like using POSIX character sets when they're applicable because they will "work" nicely with the locale and utf8 pragmas, and Unicode. When you see [a-zA-Z] in code, you're looking at code that probably won't play nice with locales. A good way to accommodate locales is POSIX character classes. So re-written with that in mind, you have this:

print "Match!\n" if $string =~ m/([[:alpha:]])\1/; # Probably good.

...instead of the possibly problematic:

print "Match!\n" if $string =~ m/([a-zA-Z])\1/; # Maybe bad!

Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://519948]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (1)
As of 2020-10-25 05:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (249 votes). Check out past polls.

    Notices?