import re anchor_re = re.compile('[^\w\d]+') def execute(hdf, args, env): return "%s" % (anchor_re.sub("", args), args.replace("'", "\\'"), args)