Raj Pathak
Raj Pathak

Reputation: 41

regex to match any number which is greater than 5

I need to match fail counts greater than 5.

string="""fail_count 7

fail_count 8

fail_count 9

fail count 7

fail_count 71

fail_count 23
"""

match = re.search(r'fail(\s|\_)count\s[5-9]', string)

if match:

    print match.group()

I am able to match up to 9, but if I increase the range to 999 it doesn't work.

Upvotes: 0

Views: 9665

Answers (2)

Nahuel Fouilleul
Nahuel Fouilleul

Reputation: 19315

5-9 or at least 2 digits

'([5-9]|\d{2,})'

or to match the whole numbre when it starts by 5-9.

5-9 followed by any number of digits or at least 2 digits

'([5-9]\d*|\d{2,})'

Upvotes: 7

Nebojsa Nebojsa
Nebojsa Nebojsa

Reputation: 1459

Maybe this regex solution can help

fail(\s|\_)count\s([0-9]{2,}|[5-9]{1})

see on regex101

Upvotes: 1

Related Questions