I am trying to construct a regular expression to detect a keyword in google search string. i.e. a string from google for a search term “amazing car” is
https://www.google.pl/#hl=pl&output=search&sclient=psy-ab&q=amazing+car&oq=amazing+car&aq=f& ... etc
I tried with this regular expression to detect a keyword car:
(google\.).+(&|\?)q=(car)
But this does not seem to work correctly. Am I missing something?
Thank you very much for advice
Your expression would match only if the query started with “car”. If you use “.*” in the group, the greedy .+ will make the “q=” match the “oq=” later in the URL.
This may work for you:
Or, safer though more complex, apply this regexp which will capture the keyword in the only capture group:
Or, if your regexp engine doesn’t support, non-capture groups, use this:
and read your keyword in the third group.