I'd like to extract from the url of a Google search the keyword of the search (e.g. for the keyword "car" : http://www.google.com/webhp?hl=en#sclient=psy&hl=en&site=webhp&source=hp&q=car&aq ... (here car is between "q=" and "&aq" but I noticed that the tokens might change ["&ie" instead of "&aq"]).
Being new at regex and Google search I haven't found so far the solution, does someone know how to do this please ?
Bruno
function getParameterByName(name,url) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(url);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
alert(getParameterByName('q','https://www.google.com/search?q=buy+a+pc&oq=buy+a+pc&aqs=chrome..69i57j5j0l2j69i61.1674j0&sourceid=chrome&ie=UTF-8#psj=1&q=buy+a+pc'));
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