Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Regex using the AND NOT operator
Hello, I'm looking for a regular expression that I find in the text, the words "ata de audiência" OR "termo de audiência", and find "inconcilia" AND "reclamante" AND "reclamada", and do NOT find the word "sentença"

    if('ata de audiência' or r'termo de audiência') and r'inconcilia' and r'reclamada' and r'reclamante' and not r'sentença',
                key_content = True
I tried to do it this way.. i can find the words, but when I use the "AND NOT" operator, the regular expression does not work

ps: there are words in portuguese
edit:I'm learning python so I'm probably taking the wrong approach
What you have, is just a bunch of strings and/or'd together, which just evaluates to True, and True isn't a regex, so it'll (probably) always fail.

I really like for putting in sample inputs that should match and fail, so I can test the regex as I write it.  In your case, since the words/phrases can appear in any order, I don't actually know offhand how to write a regex for that.  Does it HAVE to be a regex?  Because that'd be simple with just standard string searching...
text =
key_content = False
if "sentença" not in text:
    if any(phrase in text for phrase in ["ata de audiência", "termo de audiência"]):
        if all(word in text for word in ["inconcilia", "reclamada", "reclamante"])):
            key_content = True
Does the phrase need to be in this order?

ata de audiência inconcilia reclamada reclamante

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)