Home: Perl Programming Help: Regular Expressions:
finding two identical letters in a row



abcd1234
New User

Mar 3, 2010, 1:33 PM


Views: 8999
finding two identical letters in a row

Hi,

I need a regular expression to help me find two identical letters in a row from a text or a list of words, etc.

if anyone can give me more than one option and please explain why you are using what! (if possible)

thanks


shawnhcorey
Enthusiast


Mar 3, 2010, 2:11 PM


Views: 8991
Re: [abcd1234] finding two identical letters in a row

Try:

Code
#!/usr/bin/perl 

use strict;
use warnings;

for ( @ARGV ){
@_ = /(([[:alpha:]])\2)/g;
while( @_ ){
print shift(@_),"\n"; shift @_;
}
}


__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


abcd1234
New User

Mar 3, 2010, 2:15 PM


Views: 8990
Re: [shawnhcorey] finding two identical letters in a row

Okay... I just started using perl so I really don't know what that means. is there anything simpler.. just a one lined expression?


rovf
Veteran

Mar 5, 2010, 5:05 AM


Views: 8975
Re: [abcd1234] finding two identical letters in a row


In Reply To
is there anything simpler.. just a one lined expression?


Aside from the fact that you can write *every* Perl expression in one line, the regexp in the example posted *was* written in one line.

Honestly, I think this solution is already pretty compact. I understand that regexpes are hard for programming novices, so instead of asking for something simpler, you should study the example and then ask a concrete question, if you don't understand something.