5

I am receiving an error on the .match regex module function of TypeError: An integer is 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!

1
  • 3
    The 2nd argument to match() is a starting position integer, not a string. Commented Jun 15, 2015 at 16:07

2 Answers 2

7

When you re.compile a regular expression, you don't need to pass the regex object back to itself. Per the documentation:

The sequence

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

is equivalent to

result = re.match(pattern, string)

The pattern is already provided, so in your example:

pattern.match(pattern, hAndL)

is equivalent to:

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

where the third parameter to re.match is flags, which must be an integer. Instead, you should do:

pattern.match(hAndL)
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.