Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference between regex and re library #76

Open
alvations opened this issue Nov 22, 2019 · 2 comments
Open

Difference between regex and re library #76

alvations opened this issue Nov 22, 2019 · 2 comments
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@alvations
Copy link
Contributor

Would regex be faster? Or more stable?

Would changing from re to regex break the existing rules?

@alvations alvations added help wanted Extra attention is needed question Further information is requested labels Jan 6, 2020
@BLKSerene
Copy link
Contributor

BLKSerene commented Feb 23, 2020

I'm not an expert of regular expression or Python's 3rd-party library regex, but there's some general comments:

  1. AFAIK, no performance comparison between re and regex has been officially documented by the author of regex, but I suppose that since regex implements more functions, it should be slower than re, but I'm not sure whether or not the difference in speed is significant. (cf. Issue #282)
    One special case: if there's something regex can do but re cannot, and the code can be greatly simplified, then there might be a non-trivial improvement in speed. e.g. look-behinds in re must be fixed-width, but regex allows non-fixed-width look-behinds.
  2. re is part of Python's standard library and regex is a 3rd-party library, so updates on re is only released when a new version of Python is released and releases of regex can be made more frequently. So I suppose that re is more stable than regex, though that also means new features (including performance optimizations) will be added to re slower than regex (but in your case new features are not your concerns, I suppose).
  3. Changing from re to regex is not supposed to break the existing rules, as regex "is backwards-compatible with the standard ‘re’ module, but offers additional functionality" (https://pypi.org/project/regex/)

@goodmami
Copy link

goodmami commented Apr 2, 2020

From my limited experience using regex, I don't think there's a lot to gain unless you really need greater (but still not full) PCRE compatibility. I don't believe there's any noticeable performance difference (but I haven't benchmarked them). The developer of regex runs Windows only and seems to be uninterested in doing anything to better support Linux or MacOS (I hope I'm not taking this out of context; here's the thread). Also, if you use the library for better PCRE compatibility (i.e., using the V1 flag), then some warnings will become errors (here's where I encountered the same thing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants