Python regular-expression libraries

Updated Nov 2026

Python regex libraries match text against regular expression patterns with features beyond the standard library's re module. Some libraries bind a separate engine such as Hyperscan or Oniguruma rather than extending the re module. These libraries let search tools, log scanners, and AI agents match patterns against large volumes of text.

Popularity

regex has the most monthly downloads in this comparison, at 391.9M.

LibraryMonthly downloadsStarsLast releaseLicense
regex
391.9M
609Nov 2026Apache-2.0 AND CNRI-Python
google-re2
25.0M
Not on GitHubNov 2025BSD-3-Clause
hyperscan
830.6K
Not on GitHubOct 2026MIT
pyre2
315.2K
109Sep 2026BSD-3-Clause
onigurumacffi
280.7K
Not on GitHubJan 2026MIT
pyperscan
50.6K
17Oct 2026MIT OR Apache-2.0
pcre2
39.4K
Not on GitHubJul 2026BSD-3-Clause
re2
4.6K
Not on GitHubFeb 2019BSD-3-Clause
Downloads: pypi, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Features compared

LibraryStreaming scan stateReplacement APIMulti-pattern database
regexUnsupportedBuilt-inUnsupported
google-re2UnsupportedBuilt-inBuilt-in
hyperscanBuilt-inUnsupportedBuilt-in
pyre2UnsupportedBuilt-inUnsupported
onigurumacffiUnsupportedUnsupportedBuilt-in
pyperscanBuilt-inUnsupportedBuilt-in
pcre2UnsupportedBuilt-inUnsupported
re2UnsupportedBuilt-inUnsupported
Built-inNot supported

Libraries and code examples

Extends Python’s regular-expression interface with additional matching features.

Downloads / mo
391.9M
Stars
609
Last release
2026.11.15
License
Apache-2.0 AND CNRI-Python

Strengths

  • Retains repeated capture history. Use captures to retrieve every capture of a repeated named group.
  • Supports full Unicode case-folding. Enable FULLCASE with IGNORECASE for full Unicode case-insensitive matching.

Limitations

  • Fuzzy matching needs quality settings. Enable BESTMATCH when the best fuzzy result is required.
  • Concurrent matching needs unchanged input. Keep input unchanged when concurrent matching releases the GIL.

Quickstart

From README.rst
$ python -m pip install regex==2026.11.15
import regex

print(regex.search(r"\w+", "hello").group())

regex examples

From open-source projects on GitHub

Binds Google's RE2 engine to Python.

Downloads / mo
25.0M
Last release
1.1.20251105
License
BSD-3-Clause

Quickstart

From README.md
$ python -m pip install google-re2==1.1.20251105
import re2

print(re2.search(r"\w+", "hello").group())

google-re2 examples

From open-source projects on GitHub

Binds the Hyperscan engine to Python.

Downloads / mo
830.6K
Last release
0.9.1
License
MIT

Quickstart

From README.md
$ python -m pip install hyperscan==0.9.1
import hyperscan

db = hyperscan.Database()
db.compile(expressions=[b"foo"], ids=[0])
db.scan(b"foobar", match_event_handler=lambda *event: print(event))

hyperscan examples

From open-source projects on GitHub

Wraps Google’s RE2 engine behind a Python regular-expression interface.

Downloads / mo
315.2K
Stars
109
Last release
0.3.14
License
BSD-3-Clause

Strengths

  • Can reject engine fallback. Set FALLBACK_EXCEPTION when unsupported patterns must raise instead of switching engines.
  • Matches Unicode property classes. Use named Unicode classes such as Greek in patterns.

Limitations

  • Unsupported patterns switch engines. Patterns outside RE2’s syntax fall back to Python re.
  • Byte input produces byte offsets. Match offsets refer to bytes when matching UTF-8 byte strings.

Quickstart

From README.rst
$ python -m pip install pyre2==0.3.14
import re2

print(re2.search(r"\w+", "hello").group())

pyre2 examples

From open-source projects on GitHub

Binds the Oniguruma regex engine to Python through cffi.

Downloads / mo
280.7K
Last release
1.5.0
License
MIT

Quickstart

From README.md
$ python -m pip install onigurumacffi==1.5.0
import onigurumacffi

pattern = onigurumacffi.compile(r"\w+")
print(pattern.search("hello").group())

onigurumacffi examples

From open-source projects on GitHub
def search(
        self,
        line: str,
        pos: int,
        first_line: bool,
        boundary: bool,
) -> Match[str] | None:
    return self._reg.search(line, pos, flags=_FLAGS[first_line, boundary])

Provides Python bindings to the Hyperscan pattern-scanning engine.

Downloads / mo
50.6K
Stars
17
Last release
0.4.0
License
MIT OR Apache-2.0

Strengths

  • Combines multiple tagged patterns. Build a pattern database and identify matches through their tags.
  • Supports incremental stream scanning. Use StreamDatabase when matching data across stream chunks.

Limitations

  • Start offsets need a flag. Set SOM_LEFTMOST when callbacks need the match’s start offset.

Quickstart

From usage.md
$ python -m pip install pyperscan==0.4.0
import pyperscan as ps

def on_match(context, tag, start, end):
    context.append((tag, start, end))
    return ps.Scan.Continue

matches = []
db = ps.BlockDatabase(ps.Pattern(b"foo", ps.Flag.SOM_LEFTMOST))
scanner = db.build(matches, on_match)
scanner.scan(b"foobar")
print(matches)

pyperscan examples

From open-source projects on GitHub

Binds the PCRE2 regular expression library to Python.

Downloads / mo
39.4K
Last release
0.7.1
License
BSD-3-Clause

Quickstart

From README.md
$ python -m pip install pcre2==0.7.1
import pcre2

pattern = pcre2.compile(r"\w+")
print(pattern.search("hello").group())

Wraps Google's RE2 engine through Cython.

Downloads / mo
4.6K
Last release
0.2.24
License
BSD-3-Clause

Quickstart

From README.rst
$ python -m pip install re2==0.2.24
import re2

print(re2.search(r"\w+", "hello").group())

FAQ

The standard library's re module covers most patterns. regex suits code that needs repeated capture history, full Unicode case-folding, or fuzzy matching. google-re2 suits code that needs Google's regex engine. hyperscan suits scanning text against many patterns at once.

The re module supplies regular expression operations in Python's standard library. It ships with Python and needs no install.

No. The re module keeps only the last capture of a group that matches repeatedly. The regex module's captures method returns the full capture history for a named group.

No. The pattern, the input, and any replacement must share one type, either Unicode strings or bytes.

Not by default. The BESTMATCH flag changes fuzzy matching from the next match to the best match.

For coding agents

Found your regular-expression library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official