perluser4102 has asked for the wisdom of the Perl Monks concerning the following question:
I need to replace 'aa' with 'a' in a string if 'aa' occurs at the end of the word. But the characters in the string could be separated by meta data of the form: <meta_data>, where meta_data could be anything.
Please look at this snippet of code. My goal is to check if there is a character following 'aa'. When I execute this code, the "if" loop is entered. I would think the 'r' would fail a match at(^a-zA-Z*) and the if block won't be entered.
my $in_str = 'aa<c><d>r'; if ($in_str =~ /^aa((<[^>]*>)*)([^a-zA-Z]*)/) { print "Found 1: $1\n"; print "Found 2: $2\n"; print "Found 3: $3\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex question - capturing next char
by LanX (Saint) on Oct 10, 2014 at 02:12 UTC | |
by perluser4102 (Initiate) on Oct 10, 2014 at 06:11 UTC | |
by jonadab (Parson) on Oct 10, 2014 at 10:25 UTC | |
by QM (Parson) on Oct 10, 2014 at 13:43 UTC | |
by AnomalousMonk (Archbishop) on Oct 10, 2014 at 15:03 UTC | |
|
Re: Regex question - capturing next char
by Athanasius (Archbishop) on Oct 10, 2014 at 02:09 UTC | |
|
Re: Regex question - capturing next char
by Anonymous Monk on Oct 10, 2014 at 01:47 UTC |