in reply to Re^2: Regexp: How to match in middle but not the ends?
in thread Regexp: How to match in middle but not the ends?
No, he shouldn't use "+", since he doesn't want to strip any sequence of "L". For example, your solution fails to match "LL" in "---LLLL---".
My solution was lacking since I wasn't checking for an L at the start or end of the string. Fixes:
or$string =~ s/-L|L-/-/g; $string =~ s/^L//; $string =~ s/L$//;
or$string =~ s/^L|(?<-)L|L(?=-)|L$//g;
# Does a bit more than stripping, but in an inconsequential fashion. $string =~ s/^L|-L|L-|L$/-/g;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Regexp: How to match in middle but not the ends?
by Skeeve (Parson) on Jul 30, 2006 at 20:10 UTC |