import re rmf = re_match_function def re_match_function(input, re): re_compilation = re.compile(re) re_compilation.match(input) a = re_compilation.match(input) if a: print "Search was successful." print "Your match string was: %s." % (a.group()) else: print "Search was not successful. Retry?" print "Try again? (Y/N)" print "re_match_function has been defined, or 'rmf'."
I'm trying to create a function that accepts two arguments: The string to match for in a RE compilation, and a string that tells the function what to compile. When I run this code, this is the error I get when I input, for example "abc", "\D" as arguments into my function:
AttributeError: 'str' object has no attribute 'compile'
This is weird to me because I can put a string there where "re" is in the function if no function is used. This works fine for example:
re_compilation = re.compile("\d+") a = re_compilation.search("321") if a: print "Search was successful." print "Your match string was: %s." % (a.group()) else: print "Search was not successful." print "Provide another input and RE compile string to retry."
I've tried googling this to no avail. I've tried putting in arguments without quotation marks, but then this error occurs:
SyntaxError: unexpected character after line continuation character