Search code examples
phpregexpreg-matchpreg-match-all

Not able to match regex


I have a string like "5-2,5-12,15-27,5-22,50-3,5-100"

I need a regular expression which matches all the occurrences like below: -

5-2
5-12
5-22
5-100

What will be the correct regex that matches all of them.


Solution

  • Use below regex:

    (?<!\d)5-\d{1,}
    

    DEMO