in reply to Regular Expression Elegance
As others have pointed out, the key here is [^'] to keep inside the '....'.
This is a little shorter:
but requires n+1 passes across $value, where n is the maximum number of <br> between href' and '.while ($value =~ s/href='[^']*?\K<br>//gsi) {} ;
Or, following massa, above:
which does one pass only, and only processes any href'...' which contain one or more <br>. (A (?=') before the first } will stop it processing an unterminated href'...', should you care.)$value =~ s{href='[^']*?\K<br>([^']*)}{local $_ = $1, s/<br>//g, $_} +gsie;
And that fills my quota of regex finagling for the day.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regular Expression Elegance
by monkie (Novice) on Nov 11, 2008 at 16:07 UTC |