Regex to find A and not B on a line
问题 I'm looking for a regex to search my python program to find all lines where foo , but not bar , is passed into a method as a keyword argument. I'm playing around with lookahead and lookbehind assertions, but not having much luck. Any help? Thanks 回答1: If you have a string foo that you want to find and another string bar that must not be present, you can use this: ^(?!.*bar).*foo Creating a regular expression that exactly meets all your requirements is very difficult as Python code is not a