Python Regex - TypeError: Integer required

I am getting an error in the regex module function .match for TypeError: Integer required.

Here is my code:

hAndL = hAndL.replace('epsilo\ell','epsilon')
pattern = re.compile("\frac{.*?}{ \frac{.*?}{.*?}}")
matching = pattern.match(pattern,hAndL)

      

hAndL is a string and pattern is a.pattern.

I'm not sure why this error is happening, any help is appreciated!

+3


source to share


2 answers


When you're a re.compile

regex, you don't need to pass the regex object back to yourself. According to the documentation:

Sequence

prog = re.compile(pattern)
result = prog.match(string)

      

equivalent to

result = re.match(pattern, string)

      

pattern

already provided, so in your example:

pattern.match(pattern, hAndL)

      



equivalent to:

re.match(pattern, pattern, hAndL)
                # ^ passing pattern twice
                         # ^ hAndL becomes third parameter

      

where the third parameter re.match

is flags

, which must be an integer. Instead, you should do:

pattern.match(hAndL)

      

+6


source


hAndL = hAndL.replace('epsilo\ell','epsilon')
pattern = re.compile("\frac{.*?}{ \frac{.*?}{.*?}}")
matching = pattern.match(hAndL)

      



+3


source







All Articles