how can i much the sentense, if it doesn't contain none of {word1,word2,word3} where i must 开发者_JAVA百科put ^ symbol? i think it must looks like this
^([^word1|word2|word3])$
but it doesn't work. could you help? thanks
Regex isn't the best tool for testing these sorts of conditions, but if you must then you can do it with negative lookaheads:
^(?!.*word1)(?!.*word2)(?!.*word3).*$
What you are trying to do won't work because [^...]
is a negative character class with an unordered list of characters. What you wrote is equivalent to:
^([^123dorw|])$
Note also that depending on your needs you might also want to include word-boundaries in your regular expression:
^(?!.*\bword1\b)(?!.*\bword2\b)(?!.*\bword3\b).*$
im not familiar with the use of regex in htaccess, so my thoughts may be bit high level:
what you try looks like kind of: if sentence contains not word1 | not word2 | not word3 then do something
i would suggest a solution the way: if sentence contains word1|word2|word3 then do nothing else do something
means don't use the negation in the "query", but in the result, which makes the regex simpler.
精彩评论