By matching every URL except those having /something/something/13-character-group
, I'm assuming that your input strings will have characters before and after those you mentioned in your question.
First point to note: a negative lookahead is invoked with (?! ... )
(and not !?
because this means 1 !
character or none). Then, to look for this string anywhere in the URL, you will have to use a .*
before the pattern and a word boundary after the pattern:
^(?!.*/[a-zA-Z0-9-_]*/[a-zA-Z0-9-_]*/[a-zA-Z0-9]{13}\b).+$
The last .+
is to match the actual URL.