Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex everything after, but not including

Tags:

regex

I am trying to regex the following string:

https://www.amazon.com/Tapps-Top-Apps-and-Games/dp/B00VU2BZRO/ref=sr_1_3?ie=UTF8&qid=1527813329&sr=8-3&keywords=poop

I want only B00VU2BZRO.

This substring is always going to be a 10 characters, alphanumeric, preceded by dp/.

So far I have the following regex:

[d][p][\/][0-9B][0-9A-Z]{9}

This matches dp/B00VU2BZRO

I want to match only B00VU2BZRO with no dp/

How do I regex this?

like image 654
alexev31 Avatar asked Oct 14 '25 14:10

alexev31


1 Answers

Here is one regex option which would produce an exact match of what you want:

(?<=dp\/)(.*)(?=\/)

Demo

Note that this solution makes no assumptions about the length of the path fragment occurring after dp/. If you want to match a certain number of characters, replace (.*) with (.{10}), for example.

like image 92
Tim Biegeleisen Avatar answered Oct 17 '25 06:10

Tim Biegeleisen



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!