in reply to Regexp: How to match in middle but not the ends?
while ($string =~ /([CSH][CSHL]*[CSH])/g) { print "$1, "; }
Use join to avoid the trailing comma.
print join ', ', $string =~ /([CSH][CSHL]*[CSH])/g;
An alternative approach would be to strip out the offending L characters.
for ($string) { s/-L+|L+-/-/g; s/^L+//; s/L+$//; print join ', ', /([CSHL]{2,})/g; }
Update: Added s/^L// and s/L$//.
Update: Changed L to L+.
Update: Accidently changed too many things to "+"s. Fixed.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regexp: How to match in middle but not the ends?
by Skeeve (Parson) on Jul 30, 2006 at 16:59 UTC | |
by ikegami (Patriarch) on Jul 30, 2006 at 17:16 UTC | |
by Skeeve (Parson) on Jul 30, 2006 at 20:10 UTC | |
|
Re^2: Regexp: How to match in middle but not the ends?
by Hofmator (Curate) on Jul 31, 2006 at 11:08 UTC |