1

I think I may have found a bug in py regex, or have I made an error?

import regex

...

iters = regex.finditer("Teams? [^u]*? rejected",file)
for Result in iters:
    Beginning = Result.span()[0]
    End = Result.span()[1]
    Text = Result.match()

Running the above code gives the following result/error. It clearly outputs the regex.Match object with the match attribute then gives an error that the object has no attribute match.

<regex.Match object; span=(7684, 7708), match='Teams 1, 2 and 7 are rejected'>
Traceback (most recent call last):
File "b.py", line 72, in <module>
Text = Result.match()
AttributeError: '_regex.Match' object has no attribute 'match'

I wrote this code awhile ago on a different computer and it worked. Now on my new computer it gives this error. Not sure what my previous version of regex was, this is my current version.

>>pip show regex
Name: regex
Version: 2017.2.8
Summary: Alternative regular expression module, to replace re.
Home-page: https://bitbucket.org/mrabarnett/mrab-regex
Author: Matthew Barnett
Author-email: [email protected]
License: Python Software Foundation License
4
  • 1
    99.9% of the time, if you're wondering if it's a bug in popular software or you made an error, it's the latter. Commented Feb 23, 2017 at 23:21
  • I only say that because the code work fine on a previous version, now it doesn't. Commented Feb 23, 2017 at 23:22
  • The name of the standard Python regular expression module is re, not regex. Commented Feb 23, 2017 at 23:27
  • I know... I'm not using re. That's why I included the import statement. I need regex for fuzzy searching elsewhere Commented Feb 23, 2017 at 23:29

1 Answer 1

8

regex is supposed to be compatible with re. There's no match property in the Match object returned by the finditer iterator. The way to get the match for the whole regexp is with Result.group(0) or simply Result.group().

Also, Result.span()[0] and Result.span()[1] can be simplified to Result.start() and Result.end().

See the documentation of re.Match objects here

I don't know why it worked before. Maybe an older version of the regex module was exposing an internal property, and this was fixed.

Sign up to request clarification or add additional context in comments.

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.