Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by McDarren (Abbot)
on Dec 30, 2005 at 01:01 UTC ( [id://519915]=note: print w/replies, xml ) Need Help??


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

You need to use capturing parentheses, and then backreference. EG:
#!/usr/bin/perl -w use strict; while (<DATA>) { next if ($_ !~ /([A-Za-z])\1/); print; } __DATA__ balloon hello world foo bar perlmonks merry christmas

Which gives:

balloon hello foo merry

See perlre for more information.

Hope this helps,
Darren :)

Replies are listed 'Best First'.
Re^2: Using regex to match double letters, and only double letters
by kwaping (Priest) on Dec 30, 2005 at 02:51 UTC
    Good solution! I couldn't help but golf it a little. :)
    #!/usr/bin/perl -w use strict; while (<DATA>) { print if (/([a-z])\1/i); } __DATA__ balloon hello world foo bar perlmonks merry christmas
Re^2: Using regex to match double letters, and only double letters
by Anonymous Monk on Dec 30, 2005 at 02:07 UTC
    That helps immensely, thank you very much indeed. Why I didn't think of that, I shall never know.
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-23 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found