Possible Duplicate:
add or update query string parameter
I am trying to replace the page number in the query string no matter what digit is to 1.
query string
index.php?list&page=2&sort=epub
javascript
window.location.href.replace(new RegExp("/page=.*?&/"), "page=1&")
Your code looks almost right; however:
new RegExp
or the special //
regex syntax, but not both.replace
method doesn't modify the string in-place, it merely returns a modified copy..*?
, I think it makes more sense to write \d+
; more-precise regexes are generally less likely to go awry in cases you haven't thought of.So, putting it together:
window.location.href = window.location.href.replace(/page=\d+/, "page=1");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With