Let\'s say I have a string \'gfgfdAAA1234ZZZuijjk\'
and I want to extract just the \'1234\'
part.
I only know what will be the few characte
One liners that return other string if there was no match.
Edit: improved version uses next
function, replace "not-found"
with something else if needed:
import re
res = next( (m.group(1) for m in [re.search("AAA(.*?)ZZZ", "gfgfdAAA1234ZZZuijjk" ),] if m), "not-found" )
My other method to do this, less optimal, uses regex 2nd time, still didn't found a shorter way:
import re
res = ( ( re.search("AAA(.*?)ZZZ", "gfgfdAAA1234ZZZuijjk") or re.search("()","") ).group(1) )