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

Question:

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 !

Asked By: Tibo

||

Answers:

You can try this demo

(")[^ ]* ([^"]*")
Answered By: HatLess

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
Answered By: Andrej Kesely
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.