|
-
November 7th, 2005, 05:24 PM
#1
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
-
November 7th, 2005, 11:17 PM
#2
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.
*9-11-01* Never Forget; Never Forgive; Never Relent!
"If we ever forget that we're one nation under God, then we will be a nation gone under." - Ronald Reagan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|