0

I have the following regex, how do I save the value of \1 into another variable?

image_id = A8064ABAAAGAAT120108.1
version = re.sub(r'^.*?(\d+\D*)(\..*)', r'\1T\2', image_id)
4

1 回答 1

2

You'd better match the regex in the string:

pattern = re.compile('.*?(\d+\D*)(\..*)')
k = pattern.search(image_id)
saved_value = k.groups()[0] # this will give you the value 
                            # of the fist matched group
                            # as a string
于 2012-12-12T22:13:32.863 回答