a fair player a fair player - 10 months ago 62
Python Question

Python, regex dynamic count

So far I have this code:

def find_words(m_count, m_string):
m_list = re.findall(r'\w{6,}', m_string)
return m_list

is there a way to use
instead of using the count number (6) explicitly??


You can build a regex by concatenating your count variable and static part like this:

>>> m_count = 6
>>> re.findall(r'\w{' + str(m_count) + ',}', 'abcdefg 1234 124xyz')
['abcdefg', '124xyz']