Home > Mobile >  What regex can I use to "clean" a sentence from its first characters like 1), or #1, or
What regex can I use to "clean" a sentence from its first characters like 1), or #1, or

Time:11-18

I'm trying in Python to "clean up" a string and remove some characters that were added like :

"1. bla bla" => i want "bla bla"
"#. bla bla" => same
"3) bla bla" => same
"I. bla bla" => same

I tried to use (\W)(\w.*) but doesn't work.

Thanks !

CodePudding user response:

You can try:

^.[.)]\s (.*)

Regex demo.


import re

text = """\
1. bla bla
#. bla bla
3) bla bla
I. bla bla"""

pat = re.compile(r"^.[.)]\s (.*)", flags=re.M)

for cleaned in pat.findall(text):
    print(cleaned)

Prints:

bla bla
bla bla
bla bla
bla bla

CodePudding user response:

You can try this demo

(\")[^ ]* ([^\"]*\")
  • Related