I use JavaScript for regular expression. Given that I work with a well-formed source, and I want to remove any space before [,] and save only one space after [,.], Except that [,.] Is part of the number. So I use:
text = text.replace(/ *(,|\.) *([^ 0-9])/g, '$1 $2');
The problem is that this also replaces the text in the attributes of the html tag. For example, my text (always tagged):
<p>Test,and test . Again <img src="xyz.jpg"> ...</p>
Now it adds a space like this src="xyz. jpg" which is not expected. How can I rewrite my regex? I want
<p>Test, and test. Again <img src="xyz.jpg"> ...</p>
Thanks!
source share