I have an array of strings in python which each string in the array looking something like this:
<r n="Foo Bar" t="5" s="10" l="25"/>
I have been searching around for a while and the best thing I could find is attempting to modify a HTML hyperlink regex into something that will fit my needs.
But not really knowing much regex stuff I havent had anything work yet. This is what I have so far.
string = '<r n="Foo Bar" t="5" s="10" l="25"/>'
print re.split("<r\s+n=(?:\"(^\"]+)\").*?/>", string)
What would be the best way to extract the values of n, t, s, and l from that string?
This will get you most of the way there:
re.split and re.findall are complementary.
Every time your thought process begins with “I want each item that looks like X”, then you should use
re.findall. When it starts with “I want the data between and surrounding each X”, usere.split.