Where I have the bolded code is where I'm stuck. What I want to do is have the addFlags not return the new RegExp and instead change the variable object it is acting upon.Code:RegExp.prototype.addFlags = function(flags) { if(flags.match(/[^gim]/i)) return false; var newFlags = flags.split(""); var temp = this.toString(); temp = temp.substr(1, temp.length-1).replace(/\/([^\/]*)$/, "") var oldFlags = RegExp.$1; for(var i=0; i<newFlags.length; i++) { if(oldFlags.indexOf(newFlags[i])==-1) oldFlags += newFlags[i]; } return new RegExp(temp, oldFlags); //I want something like: this = new RegExp(temp, oldFlags); (If this worked that is...) }
Code:var pattern = /abc/i pattern.addFlags("gm") alert(pattern) //Currently outputs "/abc/i". I want it to output "/abc/gim" pattern = pattern.addFlags("gm") alert(pattern) //Outputs "/abc/gim"



Reply With Quote
. I read about the compile method, thinking it was like new RegExp, but it just timed faster with my tests, so I unwittingly kept it).


Bookmarks