I have a string that I need to match, which can be in various formats:
5=33
5=14,21
5=34,76,5
5=12,97|4=2
5=35,22|4=31,53,71
5=98,32|7=21,3|8=44,11
I need the numbers that appear between the equal sign (=) and pipe (|) symbol, or to the end of the line. So in the last example I need 98
,32
,21
,3
,44
,11
but I can't figure this out at all. The numbers are not concrete, they can be any quantity of numbers.
This expression will:
\d+(?=[,|\n\r]|\Z)
Live Demo
NODE EXPLANATION
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
[,|\n\r] any character of: ',', '|', '\n'
(newline), '\r' (carriage return)
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
\Z before an optional \n, and the end of
the string
--------------------------------------------------------------------------------
) end of look-ahead
Samples
With this expression the string 5=98,32|7=21,3|8=44,11
will return an array of strings:
[0] => 98
[1] => 32
[2] => 21
[3] => 3
[4] => 44
[5] => 11
You could just look for all numbers which are not followed by an equals sign
\d+(?!=|\d)
Live Demo