I am trying to set a variable. The variable should be parts of a Search query in the URL. I'm assuming to use REGE开发者_Python百科X to achieve this. IE URL: http://tsqja.deznp.servertrust.com/SearchResults.asp?Search=true+ glass&x=0&y=0
I want to pull the words 'true' and 'glass' in the example above and throw them in a jQuery variable.
ie. var newKeys = $(search keys = some code);
I am no good at using REGEX but would this just be my variable?
/^http:\/\/(tsqja\.)?deznp\.servertrust\./i,/Search=([^&]+)/i
is this for a url alone or for the current url of the page the javascript is on? if the latter, it's as simple as
location.search.split("&")[0].split("=")[1]
otherwise you could do
var url = "http://tsqja.deznp.servertrust.com/SearchResults.asp?Search=true+glass&x=0&y=0";
url.match(/[?]Search=([^&]*)/)[1];
EDIT
So something like this might work (per your comments)
var url = "http://tsqja.deznp.servertrust.com/SearchResults.asp?Search=true+glass&x=0&y=0";
var theKeys = url.split("Search=")[1].split("&")[0].replace("+"," ");
精彩评论