I'm trying to write a regex that will match a string that contains a certain substring, but fails if it also contains different substring. I've found this answer, but I'm not sure how to get it to work for my needs. In the interest of being specific as possible:
- Yes, it has to do this as part of the expression. I do not have access to the code that will be processing this.
- Yes, it needs to be one expression.
- It needs to work with PHP's regex flavor. I'm pretty sure it's being evaluated using preg
To give an idea of what I'm trying to do, I have a set of URLs I'm trying to filter. URLs that have "/somedir" in them I want to match, but I don't want it to match if it also has "somestring" in the URL.
So,
- www.somesite.com/somedir/index.html
- www.somesite.com/somedir/somotherdir/index.html
- www.somesite.com/somedir/somepage.html
would all match, but,
- www.somesite.com/somedir/somestring.html
- www.somesite.com/somedir/somestring/index.html
would both fail.