+ 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?
2 Réponses
+ 1
import re
Line = re.sub('regex', replacement, yourString)
0
.splitlines() method ignores "/n" when reading from a file. hope it helps