1 2 3 4 5 6
import re s = "RL2R'F2LD'" for m in re.finditer("[FBUDLRfbudlrxyz][2']?", s): print m.group(0)
R L2 R' F2 L D'