Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the regex to match a project tag is not working?

Tags:

python

Can anyone provide guidance on why the following regex is not working?

project = 'AirPortFamily'
line = 'AirPortFamily-1425.9:'
if re.findall('%s-(\d+):'%project,line):
    print line

EXPECTED OUTPUT:-

AirPortFamily-1425.9
like image 762
Ritz Avatar asked Dec 05 '25 07:12

Ritz


1 Answers

You should match the optional groups of digits preceded by a dot:

if re.findall(r'(%s-\d+(?:\.\d+)*):'%project,line):
like image 104
blhsing Avatar answered Dec 07 '25 19:12

blhsing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!