I would like to pass certain flags into a re.compile function based on logic similar to the below. I was wondering whether it\'s possible to do so.
flags =
re flags are just numbers. So, we need to binary OR them, like this
re
flags = 0 if multiline: flags = re.M if dotall: flags |= re.S if verbose: flags |= re.X if ignorecase: flags |= re.I if uni_code: flags |= re.U regex = re.compile(r'Test Pattern', flags)