Standalone code
def f(s):
idx = s.upper().index('S')
s = s[:idx]
for i in reversed(range(len(s))):
if s[i].isalpha():
s = s[i+1:]
break
if s.isdigit():
return int(s)
else:
return 0
Testing
print f("S2Olch1E")
#0
print f("6S2Olch1E")
#6
print f("5B66S2Olch1E")
#66
print f("54F5456B666S2Olch1E")
#666
FieldIn your expression (Field Calculator), just use:
f(!fieldName!)