Reputation: 53
Tried to find answer but didn't make it.
So, let's say I have a string
12/01/2014 22:13 1,600/1,800 *or*
12/01/2014 22:13 100/200 *or*
12/01/2014 22:13 1,600/1,800 A *or*
12/01/2014 22:13 1600/1800 A
I need to get /1,800 or /200 or /1,800 or /1800
/(\d{1,3},)*\d+.?(\d{1,8}|)
this gives me 2 matches: ex. /1,800 and /01/2014
I have found pattern to exclude dates:
(?!(0?[1-9]|1[012])([-/.])(0?[1-9]|[12][0-9]|3[01])([-/.])(19|20)\d\d)
but I don't know how to combine these two.
Upvotes: 3
Views: 15737
Reputation: 174706
You could try the below regex to match only /1,800
or /200
or /1,800
or /1800
\/(?:\d,\d{3}|\d{3,4})\b(?=[^\d]*$)
OR
\/(?:\d,\d{3}|\d{3,4})\b(?! \d)
(?! \d)
This negative lookahead asserts that the characters which are following the numbers must not be <space>
and a number. So this /01/2014
match should be failed because it's followed by a space and a number.
Upvotes: 1