0

im looking to combine multiple regexes using a AND condition. For example, the following words should not be matched (starting of string):

database
audit
index
analysis
extract
good
bad

The strings that start with these strings will not be matched. Similarly, words such as others, error will be matched.

I have done a regex that is able to filter for each word but has not been successful at filtering out the list of words to be not matched.

#This will only match those that do not start with database    
r'(^((?!database).+)'

While trying to combine, it has failed to check both conditions.

r'(^((?!database).+)(^((?!audit).+)))'

Note: This regex is to be used in the django framework, urls.py file

1 Answer 1

1

If you just want to filter out strings which start with words in your negative list, then use a negative lookahead at the start of the pattern with an alternation to cover that list of words:

^(?!database|audit|index|analysis|extract|good|bad).*$

If you wanted to check for positive matches, or wanted a more complex pattern, then you may replace .* with the appropriate logic.

Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.