Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I have the following regex, how do I save the value of \1 into another variable?
\1
image_id = A8064ABAAAGAAT120108.1 version = re.sub(r'^.*?(\d+\D*)(\..*)', r'\1T\2', image_id)
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