function replaceAll(strVal){ var regEx = /test/g; return strVal.replace(regEx,"test1"); }
What this does is replace all words "test" with "test1". If you do not want to add it globally and only want a replaceFirst method then just removed the letter "g" appended to the end of the "regEx" variable. That letter is the one that says to apply the regex globally.
No comments:
Post a Comment