• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Regex seems to be working but is not returning any matches

Resolved: Regex seems to be working but is not returning any matches

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

The complete code i have is
it seems to run fine but it returns no matches when i know the text file does infact have multiple strings that should match. Some examples of the strings in text files are as follows:
the output i am looking for would be along the lines of
Just wondering what im missing in order to actually get matches rather than it running through the code without errors and outputting nothing

Answer:

You put a ^ at the front of your regex, so it only matches at the start of the string; you could only match the very first line in your file. To allow it to match at the start of any line in a multiline string, add the re.M/re.MULTILINE flag:
Or just loop over your file by line and apply the unmodified regex:
which (assuming you wanted to find all matches) is likely a little slower than finditer on the whole file’s data at once when the file fits in memory, but means you can run against files of essentially arbitrary size.

If you have better answer, please add a comment about this, thank you!

python regex
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Time Complexity: Find the number of people who know a secret leetcode 2327

24/03/2023

Resolved: Best way to create 3d matrix of variables in PULP

24/03/2023

Resolved: Openlayers: Update clusters depending on filter (geometryFunction)

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.