in reply to Re: Regex question - capturing next char
in thread Regex question - capturing next char
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex question - capturing next char
by jonadab (Parson) on Oct 10, 2014 at 10:25 UTC | |
by QM (Parson) on Oct 10, 2014 at 13:43 UTC | |
|
Re^3: Regex question - capturing next char
by AnomalousMonk (Archbishop) on Oct 10, 2014 at 15:03 UTC |