Reputation: 783
I want to replace a comma followed by a < br > so I used regex et replace method to do that:
var str = "<a class=added> ,,, ,, blbl;test, </a><br>, <a class=added>"
str = str.replace(/br>(,\s)/g, " ");
alert(str);
In the result I noticed that 'br>' was also removed and it is not the exected result. Is there anything wrong with my regex?
"<a class=added> ,,, ,, blbl;test, </a>< <a class=added>"
Upvotes: 0
Views: 38
Reputation: 27624
You want to remove all comma followed by a white space by use following Pattern,
Check this Demo Pattern
/(\s,+)/g
Check this Demo jsFiddle
var str = "<a class=added> ,,, ,, blbl;test, </a><br>, <a class=added>"
str = str.replace(/(\s,+)/g, " ");
alert(str);
<a class=added> blbl;test, </a><br>, <a class=added>
Upvotes: 1
Reputation: 32207
You are doing the regex match correctly however you are not replacing correctly. This should be your replace string:
"br> "
as follows:
>>> str = str.replace(/br>(,\s)/g, "br> ");
"<a class=added> ,,, ,, blbl;test, </a><br> <a class=added>"
Upvotes: 1