I’ve done a regular expression to match urls following the next pattern:
part1-part2-part3.html
where
part1: is a common word
part2: is an alphanumeric word with underscores, that at least contains 2 letters
part3: is a numeric word, with 1 to 10 digits
for example a valid url would be:
news-my_news_title_200_is-12345.html
so
part1 = news
part2 = my_news_title_200_is
part3 = 12345
I’ve come to this:
/^[a-z]+-([a-z0-9_]*(?=[a-z]{2,})[a-z0-9_]*).-([0-9]{1,10})\.html$/
Expressed with classes:
/^\w+-([\w\d_]*(?=\w{2,})[\w\d_]*).-(\d{1,10})\.html$/
But I guess there’s a better way to express part2 of the R.E. pattern.
Thanks in advance.
Try this
or
Play it here