Sujet : re.DOTALL
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 17. Jul 2024, 20:09:51
Autres entêtes
Organisation : Stefan Ram
Message-ID : <DOTALL-20240717190848@ram.dialup.fu-berlin.de>
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