I have few different types of strings and want to find a particular pattern or say first number coming after the pattern in the string.Following are the example strings.
str1 = mprage_scan_0006__002.nii
str2 = fgre3d_scan_0005__001+orig.HEAD
str3 = f3dgr2_scan_7_afni_009.nii
str4 = 2dfgre_scan_09_08.nii
I want to extract numbers after 'scan_?' in every string. if it's '007' or '09' or any other way, I want to extract only the number i.e '7', '9' etc..
i did try this but looks like my solution is not that flexible as its find the first number in the string instead of first number after 'scan_' pattern.
import re
a = re.findall(r'\d+', str[i])
scan_id = re.sub("^0+","",a[0])
int(str1.split('_scan_')[1].rsplit('_')[0], 10)