Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex findall()
#1
Hi

I have re code with find findall() function. I understand that findall supposed to find a certain match in the given string, but the output that I'm getting suggest something else, I'm getting everything else except what I'm searching.

Can anybody explain to me what's happening here?

I have a xml file with this data

<?xml version="1.0" encoding="UTF-8"?>
From: [email protected]
Sent: 22 November 11:10 AM
To: [email protected]
Good day,
Claim number:   1234567
Policy number:   2468
EA Ref number:   19-24567-R-01

Client details:   Client One

She was rude
Kind regards

Person
<?xml version="1.0">
this is the code:
import re

with open('test_file.xml', 'rb') as f:
    file_content = f.read()

decoded = file_content.decode('iso-8859-1')
found = re.findall(r'encoding="UTF-8"\?>(.*?)^<\?xml version="1.0"', decoded, re.M | re.S)
print(found)
Output, It looks like the code cleaned the text: Can someone please explain this code for, why do we getthis with findall function
Output:
['\nFrom: [email protected]\nSent: 22 November 11:10 AM\nTo: [email protected]\nGood day,\nClaim number: 1234567\nPolicy number: 2468\nEA Ref number: 19-24567-R-01\n\nClient details: Client One\n\nShe was rude\nKind regards\n\nPerson\n']
Reply


Messages In This Thread
Regex findall() - by NewBeie - Jul-10-2020, 11:13 AM
RE: Regex findall() - by ndc85430 - Jul-10-2020, 11:20 AM
RE: Regex findall() - by DeaD_EyE - Jul-10-2020, 12:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  regex findall() returning weird result Radical 1 3,361 Oct-15-2023, 08:47 PM
Last Post: snippsat
  Python: re.findall to find multiple instances don't work but search worked Secret 1 2,112 Aug-30-2022, 08:40 PM
Last Post: deanhystad
  regex.findall that won't match anything xiaobai97 1 2,818 Sep-24-2020, 02:02 PM
Last Post: DeaD_EyE
  re.findall HELP!!! only returns None Rusty 10 11,911 Jun-20-2020, 12:13 AM
Last Post: Rusty
  The "FindAll" Error BadWhite 6 7,775 Apr-11-2020, 05:59 PM
Last Post: snippsat
  Beginner question: lxml's findall in an xml namespace aecklers 0 4,167 Jan-22-2020, 10:53 AM
Last Post: aecklers
  Issue with re.findall alinaveed786 8 6,921 Oct-20-2018, 09:28 AM
Last Post: volcano63
  [Regex] Findall returns wrong number of hits Winfried 8 7,705 Aug-23-2018, 02:21 PM
Last Post: Winfried
  Combining the regex into single findall syoung 0 3,008 May-28-2018, 10:11 AM
Last Post: syoung
  unable to print the list when using re.findall() satyaneel 5 5,363 Sep-27-2017, 10:26 AM
Last Post: buran

Forum Jump:

User Panel Messages

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