How to replace from regex many empty/blank characters with none? ex:
<div class="someClass" id="someID">
...bunch of elements/content
<input type="button" name="myInput" id="inputID" title="myInput Title" />
...bunch of elements/content
</div>
when replaced :
<a class="myselector" rel="I need this value"></a><div class="someClass" id="someID">...bunch of elements/content<input type="button" name="myInput" id="inputID" title="myInput Title" />...bunch of elements/content</div&开发者_如何学Cgt;
The expression \s+
will match one or more whitespace characters. Replace it with an empty string to remove them. E.g., in Python:
cleaned = re.sub(r'\s+', '', original)
If you plan to do this to HTML, you may damage it. At least replace with a single space instead:
cleaned = re.sub(r'\s+', ' ', original)
Or use a proper HTML manipulation library.
精彩评论