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.
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.
How about:
/(?<!\d)\d\-\d{1,3}/g
If understand correctly the first part of the pattern is one single digit \d
therefore we need to exclude other number with a lookbehind (?<!\d)
followed by a -
and last seems to be a number up to 3 digits if you need more you can remove the 3 and it will also work so it is either \d{1,3}
or \d{1,}
Use below regex:
DEMO