There's more than one way to do things | |
PerlMonks |
Re^2: Regex question - capturing next charby perluser4102 (Initiate) |
on Oct 10, 2014 at 06:11 UTC ( [id://1103373]=note: print w/replies, xml ) | Need Help?? |
Thanks for the replies. Let me explain my goal using a few examples: Case 1: $in_str = ‘somewordaa<metadata><moremetadata>r another wo<metadata>rd’; => aa should not be replaced by a, since aa is immediately followed by another alphabet 'r' once the metadata is ignored. Case 2: $in_str = ‘aword<metadata>aa<metadata> another wo<metadata>rd’; => aa should be replaced by a because it is at the end of a word. It is followed by space. Case 3: $in_str = 'wor<metadata>dsandmor<metadata>ewordsaa<metadata>;' => aa should be replaced by a because aa is at the end of the word (also end of string) once metadata is ignored. I now understand that the quantifier * on a negation of character class won't work because of the "0 times" match. I need to check if aa is at the end of a word. I plan to do this by checking if the following character (again, after ignoring metadata) is either a non-alphabet character or end of string. How would I go about doing this? $in_str =~ s/aa((<[^>]*>)*)([^a-zA-Z])/a$1$3/g;
In Section
Seekers of Perl Wisdom
|
|