The pattern you tried will match in both cases because the .*
will first match until the end of the string. The negative lookahead is an assertion and is non consuming which in this case asserts that, while being at then end of the string, makes sure that that there is not .htm
at the right.
That is true, as it is at the end of the string.
If 2 consecutive slashes can not occur, but there must be 2 slashes, you could use
^/[^/\r\n]+/(?!.*\.htm$)[^/\r\n]+$
Explanation
^
Start of string
/[^/\r\n]+/
Match /
, then any char except a newline or /
, then match /
again
(?!.*\.htm$)
Negative lookahead, assert that the string does not end with .htm
[^/\r\n]+
Match 1+ times any char except a newline or /
$
End of string
Regex demo
If the forward slash can occur multiple times:
^/(?:[^/\r\n]+/)*(?!.*\.htm$)[^/\r\n]+$
Regex demo