Lightning-Fast Python Regex (flpc)

0.2.5 · active · verified Fri Apr 10

flpc is a powerful Python library that wraps the blazing-fast Rust regex crate, bringing enhanced speed to your regular expression operations. It is designed to be a drop-in replacement for Python's native `re` module, with some minor syntax differences. Currently at version 0.2.5, it is in an experimental stage, meaning its code structure and dependencies may change, and users should be prepared for manual migrations to newer versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic usage of `flpc.search` for finding patterns anywhere in a string, `flpc.fmatch` for matching patterns only at the beginning of a string, and how to compile patterns for repeated use. It also highlights the use of `group(index)` for accessing captured groups.

import flpc

# Using flpc.search
text = "Hello world, hello Rust!"
pattern = r"hello (\w+)"

match_obj_search = flpc.search(pattern, text, flpc.IGNORECASE)
if match_obj_search:
    print(f"Search found: {match_obj_search.group(0)}") # group(0) for entire match
    print(f"Captured group: {match_obj_search.group(1)}")
else:
    print("No match found by search.")

# Using flpc.fmatch (equivalent to re.match, matches only at the beginning)
text_start = "Hello Python, hello flpc!"
pattern_start = r"Hello (\w+)"

match_obj_fmatch = flpc.fmatch(pattern_start, text_start)
if match_obj_fmatch:
    print(f"fmatch found: {match_obj_fmatch.group(0)}")
    print(f"Captured group: {match_obj_fmatch.group(1)}")
else:
    print("No match found by fmatch.")

# Compile a pattern for efficiency
compiled_pattern = flpc.compile(r"rust", flpc.IGNORECASE)
match_compiled = compiled_pattern.search(text)
if match_compiled:
    print(f"Compiled pattern search found: {match_compiled.group(0)}")

view raw JSON →