Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by davido (Cardinal)
on Dec 30, 2005 at 05:05 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://519948]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 05:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found