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

matlab - error with cyclic autocorrelation function -

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

c# - What is a good .Net RefEdit control to use with ExcelDna? -