I'm trying to put together a regex pattern that matches a string that does contain the word "front" and does NOT contain the word "square". I have can accomplish this individually, but am having trouble putting them together.
front=YES
^((?=front).)*$
square=NO
^((?!square).)*$
However, how to I combine these into as single regex expression?
You can use just a single negative lookahead for this:
/^(?!.*square).*front/
RegEx Demo
RegEx Details:
^: Start(?!.*square) is negative lookahead to assert a failure if text square is present anywhere in input starting from the start position.*front will match front anywhere in inputIf 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