Stefan Ram
2024-07-17 18:09:51 UTC
Below, I use [\s\S] to match each and every character.
I can't seem to get the same effect using "re.DOTALL"!
Yet the Python Library Reference says,
|(Dot.) In the default mode, this matches any character except
|a newline. If the DOTALL flag has been specified, this
|matches any character including a newline.
what the Python Library Reference says.
main.py
import re
text = '''
alpha
<hr>
gamma
<hr>
epsilon
'''[ 1: -1 ]
pattern = r'^.*?\n<hr.*?\n(.*)\n<hr.*$'
output = re.sub( pattern.replace( r'.', r'[\s\S]' ), r'\1', text )
print( output )
print( '--' )
output = re.sub( pattern, r'\1', text, re.DOTALL )
print( output )
stdout
gamma
--
alpha
<hr>
gamma
<hr>
epsilon
I can't seem to get the same effect using "re.DOTALL"!
Yet the Python Library Reference says,
|(Dot.) In the default mode, this matches any character except
|a newline. If the DOTALL flag has been specified, this
|matches any character including a newline.
what the Python Library Reference says.
main.py
import re
text = '''
alpha
<hr>
gamma
<hr>
epsilon
'''[ 1: -1 ]
pattern = r'^.*?\n<hr.*?\n(.*)\n<hr.*$'
output = re.sub( pattern.replace( r'.', r'[\s\S]' ), r'\1', text )
print( output )
print( '--' )
output = re.sub( pattern, r'\1', text, re.DOTALL )
print( output )
stdout
gamma
--
alpha
<hr>
gamma
<hr>
epsilon