Javascript : RegEx replace string
Hi,
Pretend I have the following string :
Code:
var url = "http://localhost/MyWebSite/Diagnostic.aspx:8800?ID=1&AutorefreshPage=1&AutorefreshPage=z5d1a&AutorefreshPage=1&AutorefreshPage=1&AutorefreshPage=5584&AutorefreshPage=dafx&AutorefreshPage=1225aa";
And I want to remove all occurrence of string "AutorefreshPage" from url.
So all those occurrences might be removed :
- &AutorefreshPage
- &AutorefreshPage=
- &AutorefreshPage=?...?
Here is what I did, but I'm not familliar with RegEx :(
Code:
var url = "http://localhost/QMBGateModem/Sites/BarriersDiagnostic.aspx?ID=1&AutorefreshPage=1&AutorefreshPage=254d&AutorefreshPage=21das&AutorefreshPage=ad55d&AutorefreshPage=1&AutorefreshPage=1&AutorefreshPage=2d5a5s1";
var p = url.replace( /(AutorefreshPage=)([a-zA-Z0-9]+)&/, '' );
window.alert( p );
It seem to replace only first occurence... But I think I'm far away of the solution.
Thanks for your support
Re: Javascript : RegEx replace string
A regular expression needs to be declared global in order to match/replace/etc more than one occurence. Do this simply by making your regex: /regex/g . There might be other issues, but report what happens when you do that, and we'll look to progress.