Reputation: 6566
How to parse this regex in python?
Here I need to parse the string "Miracle workers" between "From" and "date time stamp" in the efficient way.
s = """
business hours. Keyword Search: Sales, Operations, Director, Medical, Medical Devices, DME, Respiratory Equipment, Sales Rep, Account Executive, Exec, Business... <br />
From Miracle Workers - 26 Apr 2012 08:45:15 GMT
- View all <a href="http://www.indeed.com/l-Houston,-TX-jobs.html">Houston jobs</a>
"""
This is the regex i am doing.I need to get the efficient regex.
regex1 = re.findall('From\ ([A-Za-z\ ]+)\-',s)
['Miracle Workers ']
Extracting another string from url.
s2 = http://www.indeed.com/job/Region-Manager-Field-Sales-at-Covidien-in-Atlanta,-GA-a1a421aabb4d54a7"
regex2 = re.findall('-in-([A-Za-z-]+),-([A-Z]{2})',str(job.url))[0]
Here i am getting two tuples like ('Atlanta', 'GA') instead of that Need to get "Atlanta,GA"
How it supposed to do to get the results in effective way in all circumstances?
Upvotes: 0
Views: 125
Reputation: 2341
Using () your are grouping results, this way, findall give you a tuple. Try this regexp (without grouping):
regexp = '-in-[A-Za-z-]+,-[A-Z]{2}'
Upvotes: 1