Python-compatible regular expressions for TypeScript/JavaScript, mirroring Python's re/regex API.
npm install @syntropiq/py-regexPython-compatible regular expressions for TypeScript/JavaScript, powered by @syntropiq/libpcre-ts.
Provides a Pythonic API mirroring Python's re and regex modules, including named groups, escaping, and familiar match methods.
``sh`
npm install @syntropiq/py-regex
`typescript
import { regex } from '@syntropiq/py-regex';
const pattern = regex.compile('(?P
const m = pattern.fullmatch('123 456');
console.log(m?.group('volume')); // '123'
console.log(m?.groups); // { volume: '123', page: '456' }
const escaped = regex.escape('Ala. Admin. Code');
console.log(escaped); // 'Ala\\. Admin\\. Code'
`
- regex.compile(pattern: string, flags?: string): Patternregex.escape(text: string): string
- Pattern.fullmatch(text: string): Match | null
- Pattern.match(text: string): Match | null
- Pattern.search(text: string): Match | null
- Match.group(nameOrIndex: string | number): string | undefined
- Match.groups: Record
-
- Python-style named groups: (?P
- Full support for Python/PCRE regex syntax
- Familiar API for Python developers
- 100% test coverage for Python compatibility
All PCRE/Python regex logic has moved from xtrax to this package. @syntropiq/py-regex`.
For Python-compatible regex, use
MIT