LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   pattern matchin with perl (https://www.linuxquestions.org/questions/programming-9/pattern-matchin-with-perl-6954/)

gene_gEnie 09-27-2001 01:34 PM

pattern matchin with perl
 
does anyone know how to match 2 concurrent characters with perl?
i.e. If the string was wheel, im searchin for 'ee', but i dont wanna specify 'ee'
like /ee/
i want something like>>

if (/(.)\1/)
this should work but for some reason it doesnt.

Anyone any ideas?

gene_gEnie 09-27-2001 02:05 PM

What im actually searching thru' is a large text file, and i want to match every occurence of double characters, and then substitute them with brackets surrounding them,

i.e. wh(ee)l

but, because im not just searching for ee, im searching for any double character, i.e.

"Hannah had a really nice car with four wheels"

Substituted with;

"Ha(nn)ah had a rea(ll)y nice car with four wh(ee)ls"

i cant use the explicit search like /ee/

dorward 09-27-2001 03:54 PM

Erased

:Pengy:

dorward 09-27-2001 03:54 PM

This is what I use in my PHP script to match 2 or more /s

/\/{2,}/

I think the syntax for a just two is the same, but without the comma.

gene_gEnie 09-28-2001 03:41 AM

nah, that doesn't seem to work,
what does work though is

if (/([^ ])\1/)

So i search and find all occurrences of double letters and do a substitution with this line

s/$&/$&/g;

but, it only replaces the first occurrence in the line from right to left
i.e.

ha(nn)ah had a really nice car with four wheels

my book - programming perl tells me to use a while loop like this

1 while s/$&/$&/g;

but when i runit, it just seems to hang

anyone?

gene_gEnie 09-28-2001 09:26 AM

got it!

but thanks in advance anyway

$_ = $lines;
chomp $lines;
if ($lines =~ s/([^ ])\1/(\1\1)/g)
{
$t++;
print $t . " $lines\n";
}

odin 09-29-2001 11:40 PM

try:
s/((\w)\2)/\($1\)/g;


All times are GMT -5. The time now is 09:47 AM.