RegExp
Python equivalents of JavaScript RegExp type.
jstypes.JSRegExp
self, source: str, flags: JSRegExpFlag = JSRegExpFlag.NoFlag) jstypes.JSRegExp(
The data represented by a JavaScript RegExp.
Note that while Python and JavaScript Regular Expressions are similar, they each have features and syntax not supported by the other. Simple expressions will work the same in both languages, but this is not the case in general.
JSRegExp
does not support matching text with the RegExp, but as_python_pattern()
can work for patterns that use compatible syntax and flags.
Attributes
Name | Description |
---|---|
flags | |
source |
Methods
Name | Description |
---|---|
as_python_pattern | Naively compile the JavaScript RegExp as a Python re.Pattern. |
from_python_pattern | Naively create a JSRegExp with an un-translated Python re.Pattern. |
as_python_pattern
bool = True) jstypes.JSRegExp.as_python_pattern(throw:
Naively compile the JavaScript RegExp as a Python re.Pattern.
The pattern may fail to compile due to syntax incompatibility, or may compile but behave incorrectly due to differences between Python and JavaScript’s regular expression support.
from_python_pattern
jstypes.JSRegExp.from_python_pattern(
pattern: re.Pattern[AnyStr],bool = True,
throw: )
Naively create a JSRegExp with an un-translated Python re.Pattern.
As with as_python_pattern()
this can result in JSRegExp objects that won’t behave on the JavaScript side in the same way as in Python.
This can fail if the Python pattern has re.VERBOSE
set, as there’s no equivalent JavaScript flag.