re.DOTALL

Liste des GroupesRevenir à cl python 
Sujet : re.DOTALL
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.python
Date : 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

Date Sujet#  Auteur
17 Jul 24 * re.DOTALL3Stefan Ram
17 Jul 24 +- Re: re.DOTALL1Stefan Ram
18 Jul 24 `- Re: re.DOTALL (Posting On Python-List Prohibited)1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal