I have a script searching for, say, a word + "(". I'd use:
pattern = re.compile( "anyword\(" )
But I want to have users enter the pattern string from the command line (Windows 10).
argp = argparse.ArgumentParser()
argp.add_argument("-p", metavar="pattern", type=str,
, help="regex pattern")
args= argp.parse_args()
pattern = re.compile( args.p )
But it fails to handle anyword\( properly. Is there anyway to do this?
I've tried the following but none got it to re.compile(anyword\():
pattern = re.compile( bytes( args.p, "utf-8").decode('unicode_escape') )
pattern = re.compile( str.encode( args.p ).decode('unicode_escape') )
pattern = re.compile( eval( args.p) )