If you have the string foo that you want to find and another string bar that should not be present, you can use this:
^(?!.*bar).*foo
Creating a regular expression that exactly matches all your requirements is very difficult, because Python code is not a common language, but I hope you can use it as a starting point to get something good enough for your needs.
source share