Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
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.
def compile(pattern, flags=0, timeout=_UNSET):
r"""Compile ``pattern`` with the :mod:`regex` engine and wrap it so every
match runs under a wall-clock timeout.
:param pattern: a regular-expression string, or an already-compiled
``re``/``regex`` pattern (its ``.pattern`` is re-compiled with
``regex``), or an existing :class:`TimedPattern` (returned as-is with
the requested timeout).
:param flags: regex flags (stdlib ``re`` flag constants are accepted).
:param timeout: default wall-clock limit for matches on the returned
pattern; ``None`` disables it. Omit to use :data:`DEFAULT_TIMEOUT` at
match time (so a later change to that module attribute still applies).
:rtype: TimedPattern
"""
if isinstance(pattern, TimedPattern):
if timeout is _UNSET:
return pattern
return TimedPattern(pattern._rx, timeout)
# Accept a pre-compiled ``re``/``regex`` pattern by re-compiling its source. src = getattr(pattern, "pattern", pattern)
check_pattern(src)
try:
compiled = regex.compile(src, flags)
except regex.error as exc:
# Normalise the engine's error to a re.error subclass so callers that # catch re.error still work after moving off the stdlib module. raise error(str(exc)) from exc
return TimedPattern(compiled, timeout)
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.