Frage

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.

War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top