{"library":"onigurumacffi","title":"Oniguruma CFFI","description":"Onigurumacffi provides Python cffi bindings for the Oniguruma regex engine. Currently at version 1.5.0, it wraps the Oniguruma C library, offering a performant, multibyte-aware regex engine that operates primarily on bytes, distinct from Python's built-in `re` module. The library bundles the Oniguruma C source, simplifying installation, and requires Python 3.10 or newer. Releases are infrequent, tied to updates in the underlying Oniguruma library or CFFI.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install onigurumacffi"],"cli":null},"imports":["from onigurumacffi import OnigurumaRegex","from onigurumacffi import OnigurumaMatch","from onigurumacffi import OnigurumaError"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from onigurumacffi import OnigurumaRegex, OnigurumaMatch, OnigurumaError\n\n# Create a regex object. Oniguruma supports various encodings, UTF-8 is common.\n# Patterns are typically bytes for direct Oniguruma interaction.\nregex = OnigurumaRegex(b'^(hello|hi)\\\\s+(world|there)!$', encoding='utf-8')\n\n# Match a string (also bytes)\ntext = b'hello world!'\nmatch: OnigurumaMatch | None = regex.match(text)\n\nif match:\n    print(f\"Match found!\")\n    print(f\"Full match: {match.group(0).decode('utf-8')}\")\n    print(f\"Group 1: {match.group(1).decode('utf-8')}\")\n    print(f\"Group 2: {match.group(2).decode('utf-8')}\")\nelse:\n    print(f\"No match for '{text.decode('utf-8')}'\")\n\n# Example of a search (finding a substring match)\nsearch_text = b'some hello world! text'\nsearch_match: OnigurumaMatch | None = regex.search(search_text, start=0)\nif search_match:\n    print(f\"\\nSearch found!\")\n    print(f\"Search match: {search_match.group(0).decode('utf-8')}\")\n\n# Error handling\ntry:\n    invalid_regex = OnigurumaRegex(b'[invalid')\nexcept OnigurumaError as e:\n    print(f\"\\nCaught expected error: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize `OnigurumaRegex` with a byte pattern and encoding, perform `match` and `search` operations on byte strings, and access matched groups. It also includes basic error handling for invalid regex patterns.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}