Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple repeat error in python

Tags:

python

regex

I am trying some regexes in python

re.compile('in versions: (.+?) of '+name+' ')

and, if name is 'libcrypto++', cause multiple repeat error

how can i handle it only in a string..?

like image 753
haeny Avatar asked Dec 10 '17 13:12

haeny


1 Answers

+ is a quantifier in regex. So when you add libcrypto++ to regex string, it brings two of them alongside that doesn't make sense. See this.

To solve this you can use regex escape method, like:

re.compile('in versions: (.+?) of '+ re.escape(name) +' ')
like image 180
Alex Mozharov Avatar answered Oct 16 '22 01:10

Alex Mozharov