Re: Correct syntax for pathological re.search()

Liste des GroupesRevenir à cl python 
Sujet : Re: Correct syntax for pathological re.search()
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.python
Date : 07. Oct 2024, 15:56:51
Autres entêtes
Organisation : Stefan Ram
Message-ID : <backslashes-20241007145600@ram.dialup.fu-berlin.de>
References : 1
"Michael F. Stemper" <michael.stemper@gmail.com> wrote or quoted:
if not re.search("\sout\{", line):

  So, if you're not down to slap an "r" before your string literals,
  you're going to end up doubling down on every backslash.

  Long story short, those double backslashes in your regex?
  They'll be quadrupling up in your Python string literal!

  main.py

import re

lines = r'''
abcdef
\sout{abcdef
abcdef
abc\sout{def
abcdef
abcdef\sout{
abcdef
'''.strip().split( '\n' )

for line in lines:
    product = re.search( "\\sout\{", line )
    if not product:
        print( line )
   
  stdout

abcdef
abcdef
abcdef
abcdef





Date Sujet#  Auteur
7 Oct 24 * Correct syntax for pathological re.search()28Michael F. Stemper
7 Oct 24 +* Re: Correct syntax for pathological re.search()6Stefan Ram
7 Oct 24 i`* Re: Correct syntax for pathological re.search()5Michael F. Stemper
7 Oct 24 i `* Re: Correct syntax for pathological re.search()4Stefan Ram
7 Oct 24 i  +- Re: Correct syntax for pathological re.search()1Jon Ribbens
8 Oct 24 i  `* Re: Correct syntax for pathological re.search()2Pieter van Oostrum
9 Oct 24 i   `- Re: Correct syntax for re.search() (Posting On Python-List Prohibited)1Lawrence D'Oliveiro
8 Oct 24 +- Re: Correct syntax for pathological re.search()1Karsten Hilbert
8 Oct 24 +- Re: Correct syntax for pathological re.search()1MRAB
8 Oct 24 +* Re: Correct syntax for pathological re.search()3MRAB
8 Oct 24 i`* Re: Correct syntax for pathological re.search()2Stefan Ram
8 Oct 24 i `- Re: Correct syntax for pathological re.search()1Stefan Ram
8 Oct 24 +* Re: Correct syntax for pathological re.search()4Karsten Hilbert
8 Oct 24 i`* Re: Correct syntax for pathological re.search()3Alan Bawden
9 Oct 24 i +- Re: Correct syntax for pathological re.search()1MRAB
9 Oct 24 i `- Re: Correct syntax for pathological re.search()1Karsten Hilbert
11 Oct 24 +- Re: Correct syntax for pathological re.search()1<avi.e.gross
12 Oct 24 +- Re: Correct syntax for pathological re.search()1MRAB
12 Oct 24 +* Re: Correct syntax for pathological re.search()2Peter J. Holzer
12 Oct 24 i`- Re: Correct syntax for pathological re.search()1Stefan Ram
12 Oct 24 +- Re: Correct syntax for pathological re.search()1Thomas Passin
12 Oct 24 +- Re: Correct syntax for pathological re.search()1<avi.e.gross
12 Oct 24 +- Re: Correct syntax for pathological re.search()1Thomas Passin
13 Oct 24 +- Re: Correct syntax for pathological re.search()1Stefan Ram
18 Oct 24 `* Re: Correct syntax for pathological re.search()4Peter J. Holzer
19 Oct 24  `* Re: Correct syntax for pathological re.search()3jak
21 Oct 24   `* Re: Correct syntax for pathological re.search()2Peter J. Holzer
21 Oct 24    `- Re: Correct syntax for pathological re.search()1Stefan Ram

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal