Python regex findall with all specific substrings
<p>I'm trying to get the output of the following matching regex as </p>

<p>all the Sectors for eg. ['Sector-34, Noida', 'Sec 434 Gurgaon', 'sec100']</p>

<p>P.S - sec47, \n gurgaon is the special case</p>

<p>But I suspect the output is quite weird as [('', 'tor')]</p>

<pre><code>import re

string = "Sector-34, Noida is found to be awesome place I went to eat burgers there and Sec 434 Gurgoan is also good sec100 is one the finest places for outing."

match =  re.findall(r"Sec(tor)?-?\d+\s+?\w+|Sec(tor)?\s+?\d+", string, re.IGNORECASE)

print match
</code></pre>

<p>Thanks, in Advance! </p>

<p>You could go for:</p>

<pre><code>import re

rx = re.compile(r'(\b[Ss]ec(?:tor)?[- ]?\d+\b[,\s]*\b\w+\b)')

string = """
Sector-34, Noida is found to be awesome place I went to eat burgers there and Sec 434 Gurgoan is also good sec47, 
gurgaon is one the finest places for outing.
"""

sectors = [match.group(1).replace("\n", "") \
            for match in rx.finditer(string)]
print(sectors)
# ['Sector-34, Noida', 'Sec 434 Gurgoan', 'sec47, gurgaon']
</code></pre>

<p>Otherwise, please provide additional information / sectors.</p>

python regex python-2.7