Python Forum

Full Version: Need to match two words in a line
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good evening!
I'm trying to match two words and the "(" in a line.
these are" FAILED (Exit ", there is a space before the FAILED and after the Exit
here is what I come up with and it does not work... Confused
            if re.search("\sFAILED\s\(Exit",el)  : 
                print(f" ++===={el}")
                filtered.write(f"{el}"+"\n")
the regex probably looks laughable to you but that is my level of skills with regex for now.
Sorry about that. All help appreciated.
Tester.
I copied and pasted your pattern, and it worked fine for me. Maybe el does not contain what you think it contains.
import re
pattern = "\sFAILED\s\(Exit"
print(re.search(pattern, "The Search FAILED and it FAILED (Exit somewhere"))
Output:
<re.Match object; span=(24, 37), match=' FAILED (Exit'>
Awesome!
Thank you, I really appreciate your help! Smile