Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex Only Match After 2nd Forward Slash

3 string examples:

/string-to-match/1234/

/dont/1234/match/

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

/dont/match/1234/

I only want to match the first example. My curent regex matches 1 and 3:

(\/[0-9]{4}\/$)

I assume there is a way to make it only match after 2 occurances of a forward slash, but I’ve tried hundreds of search terms and cannot find an example.

Link: https://regex101.com/r/RX6Em8/1

Alternatively, doing something like this in MySQL would be sufficient, but I cannot get that working either
LIKE '/%/[0-9]{4}/'

>Solution :

Based on your question, you are not specifying where do you gonna place the regex (Python, Java, C#, etc.)

In a general way, you could try this:

Using the start (^) and end ($) string syntax I place this regex, matching the first case.

^/[^/]+/\d{4}/$

Regex101- Example

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading