Maurice
Maurice

Reputation: 477

Regex Only Match After 2nd Forward Slash

3 string examples:

/string-to-match/1234/

/dont/1234/match/

/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}/'

Upvotes: 0

Views: 127

Answers (1)

Franco Gil
Franco Gil

Reputation: 421

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

Upvotes: 2

Related Questions