Python:Regular methods use problems

>>> re.match("asd,asdasd,asd(\d)+","asd,asdasd,asd12312312").group(1)
'2'

I can't understand the result.
I think the result should be '1'
特别 张Asked:
Who is Participating?
 
Rgonzo1971Commented:
Or you could try
re.match("asd,asdasd,asd(\d)(\d)*?","asd,asdasd,asd12312312").group(1)

Open in new window

0
 
Rgonzo1971Commented:
Hi,

in REgex

A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data

re.match("asd,asdasd,asd(\d+)","asd,asdasd,asd12312312").group(1)

Open in new window

then take the first char of the found group probably with
[:1]

Open in new window

REgards
0
 
Rgonzo1971Commented:
A solution
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.