Reputation: 37
I'm using PHP preg_match_all
to parse patterns like: key1: value1, key2: value2
I reach to this regex ~([\w-_]+)\s?:\s?([^,]*)~i
it works as spected and the returned array is [['key1: value1', 'key1', 'value1'], ['key2: value2', 'key2', 'value2']]
using the PREG_SET_ORDER
arg.
BUT if I want to match text that contains a ,
so to use the text must scape with a backslash \,
is there a way in regex to skip the [^,]
breaker if it's \,
?
Upvotes: 1
Views: 41
Reputation: 174706
Use alternation operator to match escaped comma greedily.
~([\w-_]+)\s?:\s?((?:\\,|[^,])*)~i
Upvotes: 4