Python - Regex no group is found -


how add group regex?

here regex: (?<=code )(\d+)

here code:

rsize= re.compile(r'(?<=code )(\d+)') code = rsize.search(codeblock).group("code") 

how come when run code error: indexerror: no such group ? how write regex create group named code?

edit read responses, but, question is, how append regex?

the "named group" syntax little bit different:

(?p<name>group) 

example:

>>> import re >>> >>> s = "1234 extract numbers" >>> pattern = re.compile(r'(?p<code>\d+)') >>> pattern.search(s).group("code") '1234' 

Comments

Popular posts from this blog

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

matlab - error with cyclic autocorrelation function -

php - Using grpc in Laravel, "Class 'Grpc\ChannelCredentials' not found." -