Changeset 388 for python/vendor/current/Lib/re.py
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Lib/re.py
r2 r388 142 142 return _compile(pattern, flags).search(string) 143 143 144 def sub(pattern, repl, string, count=0 ):144 def sub(pattern, repl, string, count=0, flags=0): 145 145 """Return the string obtained by replacing the leftmost 146 146 non-overlapping occurrences of the pattern in string by the … … 149 149 a callable, it's passed the match object and must return 150 150 a replacement string to be used.""" 151 return _compile(pattern, 0).sub(repl, string, count)152 153 def subn(pattern, repl, string, count=0 ):151 return _compile(pattern, flags).sub(repl, string, count) 152 153 def subn(pattern, repl, string, count=0, flags=0): 154 154 """Return a 2-tuple containing (new_string, number). 155 155 new_string is the string obtained by replacing the leftmost … … 160 160 If it is a callable, it's passed the match object and must 161 161 return a replacement string to be used.""" 162 return _compile(pattern, 0).subn(repl, string, count)163 164 def split(pattern, string, maxsplit=0 ):162 return _compile(pattern, flags).subn(repl, string, count) 163 164 def split(pattern, string, maxsplit=0, flags=0): 165 165 """Split the source string by the occurrences of the pattern, 166 166 returning a list containing the resulting substrings.""" 167 return _compile(pattern, 0).split(string, maxsplit)167 return _compile(pattern, flags).split(string, maxsplit) 168 168 169 169 def findall(pattern, string, flags=0): … … 199 199 return _compile(pattern, flags|T) 200 200 201 _alphanum = {} 202 for c in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890': 203 _alphanum[c] = 1 204 del c 201 _alphanum = frozenset( 202 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") 205 203 206 204 def escape(pattern): … … 208 206 s = list(pattern) 209 207 alphanum = _alphanum 210 for i in range(len(pattern)): 211 c = pattern[i] 208 for i, c in enumerate(pattern): 212 209 if c not in alphanum: 213 210 if c == "\000":
Note:
See TracChangeset
for help on using the changeset viewer.