1
0
Fork
You've already forked pycregex
0
Pycregex, C-style POSIX.2 BRE syntax regex for Python
  • Python 76.6%
  • C 21.9%
  • Makefile 1.5%
2025年04月17日 04:08:11 -04:00
src/pycregex fix exception message 2025年04月16日 05:03:47 -04:00
tests change match to search in API 2025年04月16日 01:08:23 -04:00
.gitignore first commit 2025年04月15日 00:55:24 -04:00
COPYING first commit 2025年04月15日 00:55:24 -04:00
Makefile first commit 2025年04月15日 00:55:24 -04:00
MANIFEST.in first commit 2025年04月15日 00:55:24 -04:00
pyproject.toml fix package description in toml metadata 2025年04月17日 04:08:11 -04:00
README.md fix readme 2025年04月16日 01:10:51 -04:00
setup.py first commit 2025年04月15日 00:55:24 -04:00

Pycregex, C-style POSIX BRE (and ERE) syntax regex for Python

This package brings libc's <regex.h> API to Python. While Python has re and there's the regex package, they do not have the syntax of <regex.h>. The simplest example is the regex pattern f\(oo\) which is not supported by either of the mentioned packages, because neither supports escaping the parentheses. The syntax of <regex.h> is specified in POSIX, see the Base Specification v8 Regular Expressions chapter.

This is not a glorious API, but if you need it, here it is.

Example

We search with subgroups, and show how the subgroup begin/end indices are accessed.

import pycregex
# Note that this package only works with binary strings. nmatch is
# number of groups plus one because we must include the entire match.
p = pycregex.compile(b"f\\(oo\\)", nmatch=2)
p.search(b"foo") # ==> 0
p.span() # ==> [(0, 3), (1, 3)]