You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import re
test='''012345678
012345678
'''
pattern = r'^\s+?$'
m = re.search(pattern, test, re.M)
if m:
print(f'TEST FOUND "{m.span()}"')
def replace(m):
print(f'TEST REMOVE {m.span()}')
return ''
test = re.sub(pattern, replace, test, re.M)
m = re.search(pattern, test, re.M)
if m:
print(f'TEST STILL THERE "{m.span()}"')
print('COMPILE PATTERN FIRST')
pattern_re = re.compile(pattern, re.M)
m = re.search(pattern_re, test)
if m:
print(f'TEST FOUND "{m.span()}"')
def replace(m):
print(f'TEST REMOVE {m.span()}')
return ''
test = re.sub(pattern_re, replace, test)
m = re.search(pattern_re, test)
if m:
print(f'TEST STILL THERE "{m.span()}"')
Actual output:
TEST FOUND "(10, 19)"
TEST STILL THERE "(10, 19)"
COMPILE PATTERN FIRST
TEST FOUND "(10, 19)"
TEST REMOVE (10, 19)
This is an inconsistency between re.search and re.sub. Either this is a bug in the code or in the documentation.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: