Convert a regex regular expression to re syntax.
The first argument is the regular expression, as a string object,
just like it would be passed to regex.compile(). (I.e., pass the
actual string object -- string quotes must already have been
removed and the standard escape processing has already been done,
e.g. by eval().)
The optional second argument is the regex syntax variant to be
used. This is an integer mask as passed to regex.set_syntax();
the flag bits are defined in regex_syntax. When not specified, or
when None is given, the current regex syntax mask (as retrieved by
regex.get_syntax()) is used -- which is 0 by default.
The return value is a regular expression, as a string object that
could be passed to re.compile(). (I.e., no string quotes have
been added -- use quote() below, or repr().)
The conversion is not always guaranteed to be correct. More
syntactical analysis should be performed to detect borderline
cases and decide what to do with them. For example, 'x*?' is not
translated correctly.
Definition at line 90 of file reconvert.py.
92 """Convert a regex regular expression to re syntax.
94 The first argument is the regular expression, as a string object,
95 just like it would be passed to regex.compile(). (I.e., pass the
96 actual string object -- string quotes must already have been
97 removed and the standard escape processing has already been done,
100 The optional second argument is the regex syntax variant to be
101 used. This is an integer mask as passed to regex.set_syntax();
102 the flag bits are defined in regex_syntax. When not specified, or
103 when None is given, the current regex syntax mask (as retrieved by
104 regex.get_syntax()) is used -- which is 0 by default.
106 The return value is a regular expression, as a string object that
107 could be passed to re.compile(). (I.e., no string quotes have
108 been added -- use quote() below, or repr().)
110 The conversion is not always guaranteed to be correct. More
111 syntactical analysis should be performed to detect borderline
112 cases and decide what to do with them. For example, 'x*?' is not
113 translated correctly.
116 table = mastertable.copy()
118 syntax = regex.get_syntax()
119 if syntax & RE_NO_BK_PARENS:
120 del table[
r'\('], table[
r'\)']
121 del table[
'('], table[
')']
122 if syntax & RE_NO_BK_VBAR:
125 if syntax & RE_BK_PLUS_QM:
130 if syntax & RE_NEWLINE_OR:
143 key = table.get(key, key)