MrDevil
MrDevil

Reputation: 21

Regex for string and must not contain a number at a certain position

forums/test.654654564/44654562356456-blabla.html I want to redirect this kind of URL...

I had this RegEx ^\/forum\/.+\.([\d]+)\/([\d]+)-.+\.html$

Unfortunately, the error that also handles this URL is forums/test.654654564/44654562356456-blabla.2332423233242.html This must not be allowed to happen. Any ideas?

The rule should be that as soon as the '.html' is preceded by .\[\d+] it should be ignored. is for an nginx redirect.

Upvotes: 0

Views: 74

Answers (1)

mecode4food
mecode4food

Reputation: 320

The regular expression required can be achieved by substituting the .+ in front of the .html bit with [a-zA-Z0-9] instead:

^\/forums\/.+\.([\d]+)\/([\d]+)-[a-zA-Z0-9]+\.html$

regex test

Upvotes: 1

Related Questions