tune2fs
tune2fs

Reputation: 7705

replace all occurence of regex does not work

I have the following code:

var temp = '<p class="fasfasfasd">Type <strong>Markdown</strong> here. {:.fasfasfasd}</p>'+
                '<p class="fdfsdf">fdsfsdf {:.fdfsdf}</p>'
//this should match everything like {:*}
var re = /\{:(.*?)\}/;
console.log(temp);
temp = temp.replace(re, "", 'gm');
console.log(temp);

Here a running example: http://jsfiddle.net/AL8DN/

I want to delete all occurences of the regex re in the string temp. However the second match of the regex is never deleted. What did I wrong?

Upvotes: 0

Views: 57

Answers (1)

Katana314
Katana314

Reputation: 8610

From the Mozilla developer reference:

The use of the flags parameter in the String.replace method is non-standard. Instead of using this parameter, use a RegExp object with the corresponding flags

So, by changing this to:

var temp = '<p class="fasfasfasd">Type <strong>Markdown</strong> here. {:.fasfasfasd}</p>'+
                '<p class="fdfsdf">fdsfsdf {:.fdfsdf}</p>'
var re = /\{:(.*?)\}/gm;
console.log(temp);
temp = temp.replace(re, "");
console.log(temp);

It seems to work correctly.

Upvotes: 3

Related Questions