Javascript regex: remove space(s) if not surrounded by a letter
Posted
by
user326433
on Stack Overflow
See other posts from Stack Overflow
or by user326433
Published on 2012-09-09T09:33:38Z
Indexed on
2012/09/09
9:38 UTC
Read the original article
Hit count: 264
I'm trying to clean some html text with javascript, there are white spaces included before and after some words (text is poorly formatted).
Currently I have this regex:
$("#" + target + " *").replaceText(/([\S][\u05B0-\u05C4]*)/gi, '<span class="marked">$1<\/span>');
This will capture all the non white-space characters and wrap them in a span element, but will not capture spaces between words (I need the span).
How would you solve this?
© Stack Overflow or respective owner