Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by McDarren (Abbot)
on Dec 30, 2005 at 01:01 UTC ( #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
Node Status?
node history
Node Type: note [id://519915]
help
Chatterbox?
and the web crawler heard nothing...

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












    Results (249 votes). Check out past polls.

    Notices?