简体   繁体   中英

Matching numbers embedded in a line in perl

I am trying to write a regular expression in perl that will match this line

<sqlpurchSBC comn 23 8313364.B9230352.329 11200.00 SOLD>

my expression is this so far but it doesnt seem to match my string

m|sqlpurchSBC.*(\d+).(\d+).*(\d+).(\d+).(\d+) SOLD|

I am essentially trying to extract the value 23 and also the value 11200.00. The two decimal does not count though. I need help guys. Thanks

I think a call to split would be better here

use strict;
use warnings 'all';
use feature 'say';

my $s = '<sqlpurchSBC comn 23 8313364.B9230352.329 11200.00 SOLD>';

my @pair;
@pair = ( split ' ', $s )[2,4] if $s =~ /<sqlpurchSBC.+SOLD>/;

say "@pair";

output

23 11200.00

Try this :

m|<sqlpurchSBC.*?(\d+)\s+[\.\w]+\s+(\d+)\.?.*|
                |
          tell .* to be non greedy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM