Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6360379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:38:31+00:00 2026-05-24T23:38:31+00:00

im finding searchwords from google request urls. im using preg_match(/[q=](.*?)[&]/, $requesturl, $match); but it

  • 0

im finding searchwords from google request urls.
im using

preg_match("/[q=](.*?)[&]/", $requesturl, $match);

but it fails when the ‘q’ parameter is the last parameter of the string.

so i need to fetch everything that comes after ‘q=’, but the match must stop IF it finds ‘&’

how to do that?

EDIT:
I eventually landed on this for matching google request url:
/[?&]q=([^&]+)/
Because sometimes they have a param that ends with q. like ‘aq=0’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:38:32+00:00Added an answer on May 24, 2026 at 11:38 pm

    You need /q=([^&]+)/. The trick is to match everything except & in the query.

    To build on your query, this is a slightly modified version that will (almost) do the trick, and it’s the closest to what you have there: /q=(.*?)(&|$)/. It puts the q= out of the brackets, because inside the brackets it will match either of them, not both together, and at the end you need to match either & or the end of the string ($). There are, though, a few problems with this:

    1. sometimes you will have an extra & at the end of the match; you don’t need it. To solve this problem you can use a lookahead query: (?=&|$)
    2. it introduces an extra group at the end (not necessarily bad, but can be avoided) — actually, this is fixed by 1.

    So, if you want a slightly longer query to expand what you have there, here it is: /q=(.*?)(?=&|$)/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Finding lots of mixed answers on this from Google - but mostly 2-3 years
For Finding nth highest salary I am using select salary from ( select distinct
I am finding the Zend_Controller_Request_Abstract class quite insufficient for my application but maybe I
Finding the angle between two vectors is not hard using the cosine rule .
Tried finding the answer online, but couldn't. So i'm wondering if anyone else knows
Finding all the controls in a form by Using Reflection During the Run Time..
Task like finding factorial of 2000 where using BigInteger is a CPU-intensive task, is
Tried finding the answer myself but couldn't find a good example. So I want
Is there a way finding largest container inside a container using STL? ATM, I
I am finding many solutions to this seemingly common problem, but alas, none seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.