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? |
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/ |
Erased
:Pengy: |
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. |
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? |
got it!
but thanks in advance anyway $_ = $lines; chomp $lines; if ($lines =~ s/([^ ])\1/(\1\1)/g) { $t++; print $t . " $lines\n"; } |
try:
s/((\w)\2)/\($1\)/g; |
All times are GMT -5. The time now is 09:47 AM. |