+ 2

How to replace just a part of a pattern in a text?

Hi everyone! I'm trying to edit a ".txt" file replacing the linebreaks in paragraphs with just spaces. I started with regular expressions like this: pattern1 = r"(\D+\n)(a-z)" If I'm not wrong this would match with every line break inside a paragraph, but then I would like to replace just the "\n" with " " Somebody to help?

12th Dec 2016, 3:32 PM
Ivan Truenow
Ivan Truenow - avatar
2 Respuestas
+ 1
import re Line = re.sub('regex', replacement, yourString)
12th Dec 2016, 6:53 PM
feye
0
.splitlines() method ignores "/n" when reading from a file. hope it helps
24th Apr 2017, 4:56 PM
Alin Climente
Alin Climente - avatar