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
Post a Comment