Right now
var haystack = "Foo Bar foo bar foo bar";
var needle = "bar";
var result = haystack.replace(needle, "---");
gives
==> "Foo Bar foo --- foo bar"
ie, it will only replace first occurrence "bar"
and to get all occurrence "bar" replaced and that too with no case sensitivity
we need to pass a RegExp to the "needle" like
"Foo Bar foo bar foo bar".replace(/bar/ig, "---");
But many times the "needle" may a variable populated from user input.
Hence the ordinary web developer will have burden of converting input
text to RegExp.
Most of the webdev are not so comfortable with RegExp,
and they will start writing complex logic.
Which many times will have some bug on certain value of content text.
(that what I see, at work I support/maintain many intranet apps )
So I have proposal, can we have 3rd parameter for replace() function?
like
haystack.replace(needle, newText, regexpFlag);
where regexpFlag is the flag part of the RegExp.
And if "needle" is a string will be used to make the match characters
after "escaping" special characters like *?.()[]{}\^$|/
Cheers
Biju
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss