문제

could someone help me with my regular expression in php?

this is my regex:

(?:\d*(\,)\d*)(\,\d*)?(\,\d*)?(\,\d*)?

this is my testdata:

1~ 2,906,730 RX

1-.’ 2,733,975 Rx

/ 132,882 RX mu uuu Au

'2(*__/ 182 rX ....212

I need to match the numbers before 'RX' or 'rX' or 'Rx'. with above code the numbers in the last line don't get matched because it misses a ','.

I believe there is a better way to do this. right now my regular expression doesn't even check if its followed by 'RX'.

any help would greatly be appreciated! solution may be posted in php code.

도움이 되었습니까?

해결책

I think this will do it:

preg_match('/\d{1,3}(?:,\d{3}+)*(?= rx)/i', $data, $match);

?= is a positive lookahead -- it requires the previous regexp to be followed by this group. And i makes the regexp case-insensitive, so it will match RX, rx, or any combination.

DEMO

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top