+25
-13
lines changedFilter options
+25
-13
lines changed Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@
45
45
"|" A|B, creates an RE that will match either A or B.
46
46
(...) Matches the RE inside the parentheses.
47
47
The contents can be retrieved or matched later in the string.
48
-
(?iLmsx) Set the I, L, M, S, or X flag for the RE.
48
+
(?iLmsx) Set the I, L, M, S, or X flag for the RE (see below).
49
49
(?:...) Non-grouping version of regular parentheses.
50
50
(?P<name>...) The substring matched by the group is accessible by name.
51
51
(?P=name) Matches the text matched earlier by the group named name.
@@ -80,7 +80,6 @@
80
80
findall Find all occurrences of a pattern in a string.
81
81
compile Compile a pattern into a RegexObject.
82
82
purge Clear the regular expression cache.
83
-
template Compile a template pattern, returning a pattern object.
84
83
escape Backslash all non-alphanumerics in a string.
85
84
86
85
Some of the functions in this module takes flags as optional parameters:
@@ -90,11 +89,12 @@
90
89
"$" matches the end of lines as well as the string.
91
90
S DOTALL "." matches any character at all, including the newline.
92
91
X VERBOSE Ignore whitespace and comments for nicer looking RE's.
93
-
U UNICODE Use unicode locale.
92
+
U UNICODE Make \w, \W, \b, \B, dependent on the Unicode locale.
94
93
95
94
This module also defines an exception 'error'.
96
95
97
96
"""
97
+
98
98
import sre_compile
99
99
import sre_parse
100
100
@@ -104,7 +104,7 @@
104
104
"U", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE",
105
105
"UNICODE", "error" ]
106
106
107
-
__version__ = "2.1b2"
107
+
__version__ = "2.1.1"
108
108
109
109
# this module works under 1.5.2 and later. don't use string methods
110
110
import string
@@ -269,6 +269,9 @@ def filter(match, template=template):
269
269
b, e = m.span()
270
270
if i < b:
271
271
append(text[i:b])
272
+
elif i == b == e and n:
273
+
append(text[i:b])
274
+
continue # ignore empty match at previous position
272
275
append(filter(m))
273
276
i = e
274
277
n = n + 1
Original file line number Diff line number Diff line change
@@ -123,6 +123,10 @@ def bump_num(matchobj):
123
123
test(r"""sre.sub(r'\r\n', '\n', 'abc\r\ndef\r\n')""", 'abc\ndef\n')
124
124
test(r"""sre.sub('\r\n', '\n', 'abc\r\ndef\r\n')""", 'abc\ndef\n')
125
125
126
+
# Test for empty sub() behaviour, see SF bug #462270
127
+
test(r"""sre.sub('x*', '-', 'abxd')""", '-a-b-d-')
128
+
test(r"""sre.sub('x+', '-', 'abxd')""", 'ab-d')
129
+
126
130
if verbose:
127
131
print 'Running tests on symbolic references'
128
132
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
31
31
* 2001-04-28 fl added __copy__ methods (work in progress)
32
32
* 2001-05-14 fl fixes for 1.5.2
33
33
* 2001-07-01 fl added BIGCHARSET support (from Martin von Loewis)
34
+
* 2001-09-18 fl
34
35
*
35
36
* Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
36
37
*
@@ -133,6 +134,8 @@ static char copyright[] =
133
134
#define SRE_ALNUM_MASK 8
134
135
#define SRE_WORD_MASK 16
135
136
137
+
/* FIXME: this assumes ASCII. create tables in init_sre() instead */
138
+
136
139
static char sre_char_info[128] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 6, 2,
137
140
2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
138
141
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, 25, 25, 25, 25, 25, 25,
@@ -1141,6 +1144,7 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level)
1141
1144
}
1142
1145
1143
1146
/* can't end up here */
1147
+
/* return SRE_ERROR_ILLEGAL; -- see python-dev discussion */
1144
1148
}
1145
1149
1146
1150
LOCAL(int)
@@ -2624,16 +2628,17 @@ init_sre(void)
2624
2628
m = Py_InitModule("_" SRE_MODULE, _functions);
2625
2629
d = PyModule_GetDict(m);
2626
2630
2627
-
PyDict_SetItemString(
2628
-
d, "MAGIC", (x = (PyObject*) PyInt_FromLong(SRE_MAGIC))
2629
-
);
2630
-
Py_XDECREF(x);
2631
-
2632
-
PyDict_SetItemString(
2633
-
d, "copyright", (x = (PyObject*)PyString_FromString(copyright))
2634
-
);
2635
-
Py_XDECREF(x);
2631
+
x = PyInt_FromLong(SRE_MAGIC);
2632
+
if (x) {
2633
+
PyDict_SetItemString(d, "MAGIC", x);
2634
+
Py_DECREF(x);
2635
+
}
2636
2636
2637
+
x = PyString_FromString(copyright);
2638
+
if (x) {
2639
+
PyDict_SetItemString(d, "copyright", x);
2640
+
Py_DECREF(x);
2641
+
}
2637
2642
}
2638
2643
2639
2644
#endif /* !defined(SRE_RECURSIVE) */
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4