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:
need to create regex which match duplicate chacter in a word

 



annie_perl
Novice

Aug 19, 2009, 10:48 PM

Post #1 of 3 (3094 views)
need to create regex which match duplicate chacter in a word Can't Post

HI ,

I have an array and i need create a regex which will match any word that contains a double
#letter, for example "book" has a double "o" and "feed" has a double "e".

Here is the sytax i have created to check only 'a' and 'r' character. what i needed is what is the regex to check the duplication characters from a-z in 2 or more characters. I tried [(a-z){2,}]

your help is highly appreciated!



my $value;
my $output;

foreach $value(@string){

$output=($value=~m/(a{2,}|r{2,})/g);
if($output){print $`,$1,$'."\n"; }
}


annie_perl
Novice

Aug 19, 2009, 11:01 PM

Post #2 of 3 (3092 views)
Re: [aan] need to create regex which match duplicate chacter in a word [In reply to] Can't Post

Basically i need a short regex instead of the long regex as following:

(a{2,}|b{2,}|c{2,}|d{2,}|e{2,}|f{2,}|g{2,}|h{2,}|
i{2,}|j{2,}|k{2,}|l{2,}|m{2,}|n{2,}|o{2,}|p{2,}|
q{2,}|r{2,}|s{2,}|t{2,}|u{2,}|v{2,}|w{2,}|x{2,}|
y{2,}|z{2,})


KevinR
Veteran


Aug 20, 2009, 9:38 AM

Post #3 of 3 (3087 views)
Re: [annie_perl] need to create regex which match duplicate chacter in a word [In reply to] Can't Post


Code
@w = qw (these those that book took crook feed weed seed you me them); 
for (@w) {
print "$_\n" if /([a-z])\1/;
}

-------------------------------------------------

 
 


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

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