(Mar-04-2024, 09:07 PM)tester_V Wrote: Greetings!
I’d like to match strings in files, it seems simple but I’m failing to do this…
It has multiple white spaces before the word Start Time or End Time and the Time and Date of the event
String “ Start Time 2/28/2024 8:34:34 AM ”I tried :
if re.search("\s+\Start\s\Time",el) : # < ------------- el is a line from the file ,,, print(f" START LN {el}")And got an error message “ bad escape \T at position 11”
Then I tried:
if re.search("\s+\Start\s\",el) : # < ------------- el is a line from the file ,,, print(f" START LN {el}")This one prints tons of other lines I do not care about.![]()
I was sure by using “\s+” would filter the line I wanted but it does not.
Would you help me with this?
Thank you.
It seems like you're encountering issues with your regular expression syntax. Here's how you can correct it:
import re # Sample line from the file el = " Start Time 2/28/2024 8:34:34 AM" # Use raw string literal to avoid escaping issues if re.search(r"\s+Start\s+Time", el): print(f"START LN {el}")In this corrected version:
I used a raw string literal (r"...") for the regular expression to avoid issues with backslashes.
I adjusted the regular expression to \s+Start\s+Time, which matches one or more whitespace characters before and after "Start Time".
i hope This should correctly filter the lines containing "Start Time" as you intended.
Best Regard
Danish Hafeez | QA Assistant
buran write Mar-05-2024, 05:55 AM:
Clickbait link removed
Clickbait link removed