Reputation: 414
I'm trying to figure out how to put option values in a lookaround with regular expressions.
These values should match
3
1000
15-20
2048-4096/100
This value should not
3/4
I want to say in regex "only match if there is a dash 4 digit number and a colon preceding the / division symbol
For example:
-9999
preceding the /
division symbol should match9999/
should not match because there is no --/
should not match because there is no number
^[^0][0-9]*(-|:)?([0-9]*)?(?<=[0-9])(\/)?([0-9]*)$
I have the look around just looking for a preceding number but if I put a ?
or *
in it it no longer works. Thanks for the help!!!
Upvotes: 0
Views: 42
Reputation: 3574
^\d+(?:[-:](?:\d{4}\/\d+|\d+))?$
If I'm understanding what you want correctly,
Upvotes: 2