Reputation: 3492
I have some text:
1. Lorem «ipsum» dolor sit amet, consectetur<br/>
2. adipisicing «elit», sed do eiusmod tempor<br/>
3. incididunt ut «labore» et dolore magna aliqua.<br/>
And I want to replace all "&laquo;
" to "&#171;
" and all "&raquo;
" to "&#187;
".
This replace only in first row:
txt.replace(new RegExp("&laquo;","gi"),"&#171;").replace(new RegExp("&raquo;", "gi"),"&#187;");
other rows still not changed.
What I am doing wrong?
Upvotes: 5
Views: 420
Reputation: 3157
use this
txt.split( "&laquo;" ).join( "&#171;" ).split( "&raquo;" ).join( "&#187;" );
split breaks your string into an array of pieces connected by the text in the parameter. join glues the pieces back into a string and inserts the parameter between each piece :D
Note that each method creates an array (the pieces) or a string (the glued together pieces) so you should do txt = txt.split(...
Upvotes: 1