Created
November 12, 2015 21:39
-
-
Save kennethlove/906bb89fe73c95362636 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'<div>\n' | |
' <p>This is a bunch of stuff it has new lines everywhere.</p>\n' | |
" <p>and we don't need them</p>\n" | |
' <pre>But\n' | |
' we do\n' | |
'need these\n' | |
'</pre>\n' | |
" <p>let's see what we can do!</p>\n" | |
'</div>\n' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pprint | |
import re | |
SAFE_PRE = r'(?<!(\<pre\>))({})(?!(\<\/pre\>))' | |
RE_MULTISPACE = re.compile(SAFE_PRE.format(r"\s{4,}")) | |
RE_NEWLINE = re.compile(SAFE_PRE.format(r"(\n{2,})")) | |
input_string = """<div> | |
<p>This is a bunch of stuff it has new lines everywhere.</p> | |
<p>and we don't need them</p> | |
<pre>But | |
we do | |
need these | |
</pre> | |
<p>let's see what we can do!</p> | |
</div> | |
""" | |
#pprint.pprint(RE_MULTISPACE.sub(' ', input_string)) | |
pprint.pprint(RE_NEWLINE.sub('\n', input_string)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment