Regex For Letters and Numbers Within URL

677 views Asked by At

I'm trying to match some URLS as a proof of concept using Golang. I'm not the best with regular expressions, I need something that matches anything with either a season number or episode number following a backslash. Here's an example:

https://URL.com/program/something-a/s1/e1/title
https://URL.com/program/something-a/e12/title

The seasons can go up to double figures (/s12, /s13), and the episodes up to three (e.g. /e100). What's the best way to do this?

Edit: So here's what I tried so far:

(\/s.\/)

or

(\/e.\/)

Seems to work for single figures, but not when you get up to something like /e12/ etc. When I try to find something that matches both, like

(\/s[0-9][0-9]\/)

it doesn't pick up episodes or series with only a single number (e.g. /s2/).

1

There are 1 answers

0
Vorsprung On BEST ANSWER
s(\d{1,2})/e(\d{1,3})

how it works

  • s matches letter s
  • ( start of submatch capture group
  • \d match a single digit
  • {1,2} at least 1 no more than 2 of the previous expression (which is a digit)
  • ) end of capture group
  • / literal slash character
  • e matches letter e

...and then there is another sequence but for 3 digits, not 2