Quicker but no regex:
javascript:window.location.href = window.location.href.replace("review?","close?");
Question
Sorry folks, I've been poking around StackOverflow for awhile but can't seem to garner enough information to fix my problem here. I'm not very adept with regex, or the use of javascript in bookmarklets. Hoping someone can help me fix this little problem.
I would like this:
To become this:
" " " " " /close?set=123456
Obviously placeholder information (not that hard to figure out what it's for haha), but the sections abcd are ALWAYS there and always the same, it's just the very end piece that changes while retaining the variable number at the end.
Here's what I have that doesn't work:
javascript:window.location=window.location.href.replace(/.+set=(\d+).+/i,'http://www.example.com/a/b/c/d/close?set=$1');
Every time I use the bookmarklet, instead of loading the page properly, it just falls flat and does nothing. However if I manually change the correct piece of the URL, it behaves properly... I think I'm doing something wrong and I think it's very simple.
The numbers at the end are variable in both value and number. Every other piece remains static.
Any advice?
Solution
Quicker but no regex:
javascript:window.location.href = window.location.href.replace("review?","close?");
OTHER TIPS
You probably want to replace
/.+set=(\d+).+/i
with
/.+set=(\d+).*/i
The +
matches one or more of whatever precedes it.