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


Views: 6048
need to create regex which match duplicate chacter in a word

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


Views: 6046
Re: [aan] need to create regex which match duplicate chacter in a word

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


Views: 6041
Re: [annie_perl] need to create regex which match duplicate chacter in a word


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

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