Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex remove pattern from match

Tags:

date

regex

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.

like image 218
big.tuna Avatar asked Mar 25 '26 20:03

big.tuna


2 Answers

.*(\/\S+)

This simple regex should work for you.

See demo

like image 193
vks Avatar answered Mar 28 '26 18:03

vks


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]*$)

DEMO

OR

\/(?:\d,\d{3}|\d{3,4})\b(?! \d)

DEMO

(?! \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.

like image 36
Avinash Raj Avatar answered Mar 28 '26 18:03

Avinash Raj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!