iregexp-check
iregexp-check is a Python library providing bindings to a Rust crate for working with I-Regexp, an interoperable regular expression format. It allows Python developers to validate and interact with I-Regexp patterns. The library is actively maintained with regular updates and is currently at version 0.1.4.
Common errors
-
ModuleNotFoundError: No module named 'iregexp_check'
cause The `iregexp-check` library is not installed in the current Python environment, or the environment is not correctly activated.fixEnsure the package is installed: `pip install iregexp-check`. -
TypeError: argument 'pattern' must be str, not int
cause The `is_valid_iregexp` function (or similar functions in the library) expects a string argument for the regular expression pattern, but a non-string type was provided.fixEnsure that the pattern passed to the function is always a string. For example, `is_valid_iregexp("foo")` instead of `is_valid_iregexp(123)`.
Warnings
- gotcha I-Regexp (Interoperable Regular Expression Format) has a specific syntax which may differ from common regular expression engines like PCRE (Perl Compatible Regular Expressions) or Python's `re` module. Patterns valid in other regex engines might be invalid or behave differently in I-Regexp.
- gotcha When defining regular expression patterns in Python, especially those with backslashes, always use raw strings (prefix the string literal with 'r', e.g., `r'\d+'`). This prevents Python's string literal processing from interpreting backslashes as escape sequences before the regular expression engine sees them, avoiding unexpected behavior or `SyntaxWarning`s.
Install
-
pip install iregexp-check
Imports
- is_valid_iregexp
from iregexp_check import is_valid_iregexp
Quickstart
from iregexp_check import is_valid_iregexp
# Example 1: A valid I-Regexp pattern
pattern_valid = "o.o|aa"
print(f"'{pattern_valid}' is valid: {is_valid_iregexp(pattern_valid)}")
# Example 2: An invalid I-Regexp pattern (e.g., unmatched parenthesis)
pattern_invalid = "(abc"
print(f"'{pattern_invalid}' is valid: {is_valid_iregexp(pattern_invalid)}")
# Example 3: Another valid I-Regexp pattern
pattern_simple = "foo"
print(f"'{pattern_simple}' is valid: {is_valid_iregexp(pattern_simple)}")