Python Forum
Need to match two words in a line
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need to match two words in a line
#1
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.
Reply
#2
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'>
tester_V likes this post
Reply
#3
Awesome!
Thank you, I really appreciate your help! Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,822 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  Open and read multiple text files and match words kozaizsvemira 3 6,767 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  If match not found print last line tester_V 2 2,897 Apr-26-2021, 05:18 AM
Last Post: tester_V
  item from a line to list however when i print the line instead of words i get letters Sutsro 5 2,981 Apr-22-2020, 02:39 PM
Last Post: deanhystad
  How do you replace a word after a match from a list of words in each line of a file? vijju56 1 3,477 Oct-17-2019, 03:04 PM
Last Post: baquerik
  Counting words in the last line of a file Drone4four 15 6,538 May-31-2019, 09:30 PM
Last Post: snippsat
  Compare all words in input() to all words in file Trianne 1 2,776 Oct-05-2018, 06:27 PM
Last Post: ichabod801
  How to find unique and common words per line from a txt file? sweet_swiss 6 4,302 Aug-11-2018, 01:28 PM
Last Post: Gribouillis
  Compare element of list with line of file : if match, delete line silfer 4 3,527 Jul-21-2018, 02:44 PM
Last Post: silfer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020