I need to capture the digits (ids) from a "|" delimited string, This is an example string:
|98|34|2|{"flag":"CHART"}
This is the expression that seem to work (for the first digit)
^\|(\d+)\|
The problem is that this only captures the first digit.
I don't know how to make this regex repeat itself till it reaches the "{" symbol. Help would be appreciated!
And please tell me if there is a more efficient way to do this (in php)
Use the \G anchor to start the next match on the same string where the last match left off.
(?:^\||\G)\|?(\d+)(?=\|)
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With