0

The function is as follow:

def user_regex(regex_type, regex, test_string):
        my_regex = re.regex_type(regex, test_string)
        #...

Which cause this error:

AttributeError at /

module 're' has no attribute 'regex_type'

Of course the user chooses between findall, sub etc. when the function is called in my script.

MisterMiyagi
  • 44,374
  • 10
  • 104
  • 119
Takamura
  • 347
  • 5
  • 12
  • 1
    What is ``regex_type``? Is it a string, as in ``"findall"``, or an actual regex "type", as in ``re.findall``? – MisterMiyagi Aug 05 '21 at 10:07
  • @MisterMiyagi it's a string – Takamura Aug 05 '21 at 10:27
  • 2
    If you want to call `re.match` from inside the function, you don't need to (and preferably shouldn't) pass the string `"match"`; you should just pass the function `re.match` itself. `def user_regex(regex_func, regex, test_string): my_regex = regex_func(regex, test_string) ...`, then `x = user_regex(re.match, "f.*", "foo")`. – chepner Aug 05 '21 at 10:32
  • Thanks @chepner, post it as an answer and I'll accept it – Takamura Aug 05 '21 at 13:51

0 Answers0