Eazy
Eazy

Reputation: 3492

Action Script 3.0 replace all occurrences in multiline String

I have some text:

1. Lorem &laquo;ipsum&raquo; dolor sit amet, consectetur<br/>
2. adipisicing &laquo;elit&raquo;, sed do eiusmod tempor<br/>
3. incididunt ut &laquo;labore&raquo; et dolore magna aliqua.<br/>

And I want to replace all "&amp;laquo;" to "&amp;#171;" and all "&amp;raquo;" to "&amp;#187;".

This replace only in first row:

txt.replace(new RegExp("&amp;laquo;","gi"),"&amp;#171;").replace(new RegExp("&amp;raquo;", "gi"),"&amp;#187;");

other rows still not changed.

What I am doing wrong?

Upvotes: 5

Views: 420

Answers (2)

Tair
Tair

Reputation: 3819

Make your regex 'multiline':

new RegExp("&amp;laquo;","gim")

Upvotes: 8

Discipol
Discipol

Reputation: 3157

use this

txt.split( "&amp;laquo;" ).join( "&amp;#171;" ).split( "&amp;raquo;" ).join( "&amp;#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

Related Questions