CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



abcd1234
New User

Mar 3, 2010, 1:33 PM

Post #1 of 4 (4355 views)
finding two identical letters in a row Can't Post

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

Post #2 of 4 (4347 views)
Re: [abcd1234] finding two identical letters in a row [In reply to] Can't Post

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

Post #3 of 4 (4346 views)
Re: [shawnhcorey] finding two identical letters in a row [In reply to] Can't Post

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

Post #4 of 4 (4331 views)
Re: [abcd1234] finding two identical letters in a row [In reply to] Can't Post


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.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives