in reply to Re: How can i extract a number from an string
in thread How can i extract a number from an string
An alternative to JavaFan's use of a capture in the split regexp could be to use look-arounds to do the split at points where the string changes from non-digit to digit and vice-versa. I think JavaFan's method is better in this case but the look-arounds can sometimes be a useful technique.
$ perl -le ' > $_ = q{BS123-bleble}; > print +( split m{(?x) (?: (?<=\D)(?=\d) | (?<=\d)(?=\D) )} )[ 1 ];' 123 $
I hope this is of interest.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How can i extract a number from an string
by Sombrerero_loco (Beadle) on Jan 23, 2009 at 11:02 UTC |