I'm trying to retrieve all the tags containing a 'name' field, and then treat the whole sentence plus the name. This is the test code I have:
sourceCode = '<dirtfields name="one" value="stuff">\n<gibberish name="two"\nwewt>'
namesGroup = re.findall('<.*name="(.*?)".*>', sourceCode, re.IGNORECASE | re.DOTALL)
for name in namesGroup:
print name
Which output is:
two
And the output I am trying to look for would be
['<dirtfields name="one" value="stuff">', 'one']
['<gibberish name="two"\nwewt>', 'two']
EDIT: Found a way to do it, thanks to doublesharp for the cleaner way to get the 'name' value.
namesGroup = re.findall(r'(<.*?name="([^"]*)".*?>)', sourceCode, re.IGNORECASE | re.DOTALL)
Which will output:
('<dirtfields name="one" value="stuff">', 'one')
('<gibberish name="two"\nwewt>', 'two')