Python Forum
unable to replcae a pattern using method re.sub()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unable to replcae a pattern using method re.sub()
#1
my question here
I am unable to replace a pattern using the method re.sub()
import re

#initialize string

x='<?xml version="1.0" encoding="UTF-8"?><rule stage="Source">'

#extracting a part of string

b=re.findall('(<.+\s.+\?>)',x) ##result will be b=['<?xml version="1.0" encoding="UTF-8"?>']

#now I want to remove the extract part so I am using

print(re.sub(b[0],'',x))
# expected result is <rule stage="Source"> how ever I am getting <?xml version="1.0" encoding="UTF-8"?#><rule stage="Source"> please help
Reply


Messages In This Thread
unable to replcae a pattern using method re.sub() - by Jeevananda - Aug-15-2017, 03:06 PM

Forum Jump:

User Panel Messages

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