MATLAB: Specific pattern from the file name

MATLABregexspecific pattern file name

I want to extract the project number from the file name
example the file fame is: 'abcdd-22_Z12'
the project number should be Z12 for sure it is dynamic name could in the next file name Z11 for intance.
which expression I should use

Best Answer

These statements
%%
chr = 'abcdd-22_Z12';
cac = regexp( chr, '(?<=_)Z\d{2}', 'match' );
cac{:}
return
ans =
'Z12'
This regex, '(?<=_)Z\d{2}', matches a literal "Z" followed by two digits, which is preceded by underscore.