I have those strings:
"/page/test/myimg.jpg"
"/page/test/"
"/page2/test/"
"/page/test/other"
I want true for all strings starting with /page/test except when it ends with .jpg
.
Then I did: /^\/page\/test(.*)(?!jpg)$/
.
Well, it's not working. :\
It should return like this:
"/page/test/myimg.jpg" // false
"/page/test/" // true
"/page2/test/" // false
"/page/test/other" // true
Use a negative look behind anchored to end:
/^\/page\/test(.*)(?<!\.jpg)$/
For clarity, this regex will match any input that *doesnt end in .jpg
:
^.*(?<!\.jpg)$
JavaScript doesn't support look behinds, so this ugly option must be used, which says that at least one of the last 4 characters must be other than .jpg
:
^.*([^.]...|.[^j]..|..[^p].|...[^g])$
Easily done with JavaScript:
/^(?!.*\.jpg$)\/page\/test/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With