I would like to determine whether a string S has a substring MYSUBSTRING preceded by two consecutive digits I need to determine.
For example:
‘aaa79bbbMYSUBSTRINGccc’
==> I want 7, 9 and True (or 7, 9 and MYSUBSTRING)
‘aaa79bbbccc’
==> I want 7, 9 and False (or 7, 9 and None)
Can I do that with a SINGLE regex? If so, which one?
The following regex should do it:
(\d)(\d)(?:.*?(MYSUBSTRING))?