Ask a Question
Advertise on boostr.in
Organizational Research By
Surprising Reserch Topic
how to Trimming Whitespace using regular-expression?
You can easily trim unnecessary whitespace from the start and the end of a string or the lines in a text file by doing a regex search-and-replace. Search for ^[ \t]+ Â and replace with nothing to delete leading whitespace (spaces and tabs). Search for [ \t]+$ Â to trim trailing whitespace. Do both by combining the regular expressions into ^[ \t]+|[ \t]+$ . Instead of [ \t] which matches a space or a tab, you can expand the character class into [ \t\r\n] if you also want to strip line breaks. Or you can use the shorthand \s instead.
Sep 13, 2013
Sep 12, 2013
to add a comment.
Related Hot Questions
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
To avoid this verification in future, please