Python Forum
[Regex] Findall returns wrong number of hits
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Regex] Findall returns wrong number of hits
#3
Thanks.

So I removed 2.7.14, installed 3.7.0*, re-ran the code, and… same error: Wrong number of hits:

import re,sys,locale

# Open file
f = open('input.gpx', 'r')
#GOOD strings = re.findall(r'<trk>', f.read())

#Only 27!
#BAD strings = re.findall(r'<trk>.+?</trk>', f.read())

#Only 27!
p = re.compile(r'(<trk>.+?</trk>)',re.MULTILINE)
strings = p.findall(f.read())

f.close()

if strings:
	#27 instead of 348!
	print("Number of items : " + str(len(strings)))
* Checked that "python -V" returns "Python 3.7.0"
Reply


Messages In This Thread
RE: [Regex] Findall returns wrong number of hits - by Winfried - Aug-21-2018, 04:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  regex findall() returning weird result Radical 1 656 Oct-15-2023, 08:47 PM
Last Post: snippsat
  np.percentile returns wrong value? AceTylercholine 2 668 Jul-13-2023, 06:59 PM
Last Post: Skaperen
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,579 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Python: re.findall to find multiple instances don't work but search worked Secret 1 1,231 Aug-30-2022, 08:40 PM
Last Post: deanhystad
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,637 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  '|' character within Regex returns a tuple? pprod 10 5,608 Feb-19-2021, 05:29 PM
Last Post: eddywinch82
  regex.findall that won't match anything xiaobai97 1 2,036 Sep-24-2020, 02:02 PM
Last Post: DeaD_EyE
  Please support regex for version number (digits and dots) from a string Tecuma 4 3,210 Aug-17-2020, 09:59 AM
Last Post: Tecuma
  Programme will not returns the day number not the day name Oldman45 8 3,061 Jul-27-2020, 11:29 AM
Last Post: Oldman45
  Regex findall() NewBeie 2 4,307 Jul-10-2020, 12:19 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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