I want to match strings like those below.
abc|q:1,f:2
cba|q:1,f:awd2,t:3awd,h:gr
I am using php and have tried both preg_match and preg_match_all with this expression.
/^([a-z]+)\|([a-z]+:[a-z0-9]+,?)+$/iU
This only returns the first part before the pipe, and one a:1. What am I doing wrong, why is it behaving this way and how can I make it work?
would capture:
The greedy nature of the ‘+’ quantifier make your capturing group ([a-z]+:[a-z0-9]+,?) only capture the last set of characters matching this regex.
would capture the all line.
Note the ‘
?:‘ to avoid creating any capturing group.