fawzib fawzib - 2 years ago 68
SQL Question

match line that doesnt contain certain words

I have the following string:

ignoreword1,word1, ignoreword2

i would like to match any word that is not

this is what i have so far


the main goal is to use the regex as part of postgresql database to select rows where the column match a substring after removing "ignoreword1", "ignoreword2" and the comma ","

Answer Source

To match any word that is not ignoreword1 or Ignoreword2 use 


In PostgreSQL, word boundaries are [[:<:]] and [[:>:]], so use something like:


Pattern details:

  • [[:<:]] - leading word boundary
  • (?!(?:ignoreword1|ignoreword2)[[:>:]]) - fail the match if the whole string is either ignoreword1 or ignoreword2
  • [a-zA-Z]+ - one or more any ASCII letters.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download