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 8454995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:10:20+00:00 2026-06-10T12:10:20+00:00

Possible Duplicate: Get query string values in JavaScript I had this pattern but it

  • 0

Possible Duplicate:
Get query string values in JavaScript

I “had” this pattern but it didn’t quite give me what I need, though it worked.

var regex = new RegExp('\\b' + data.keyword + '(=[^&]*)?(&|$)',"gi");

But the following regular expressions “is” what I need but i can’t seem to get it to work within the regex obj:
/&dyanmicTxtHere(\=[^&])?(?=&|$)|^dyanmicTxtHere(\=[^&])?(&|$)/

I tried: This is NOT working –

var regex = new RegExp('&' + data.keyword + '(=[^&]*)?|^' + data.keyword + '(=[^&]*)?&?',"gi");

I can’t figure out why. So the above regex should strip out my passed param (and vlaue)(data.keyword), and deal with the ? and & wherever that param sits in the url. It

So, what would this match?

http://www.someurl.com?Keyword=foo

http://www.someurl.com?up=down&Keyword=foo

http://www.somurl.com?up=down&keyword=foo&left=right

etc… so, if I passed in “Keyword” as my dynamic param, then it would remove it and its associated value.

  • 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-06-10T12:10:21+00:00Added an answer on June 10, 2026 at 12:10 pm

    Obviously what follows is not a regular expression; but it should, I think, fulfil your requirements. It takes advantage of the requirements of name-value pairs in a GET query-string, and uses simple string, and some array, manipulation to examine the various (if any) name-value pairs from the passed URL:

    function removeParam(url, param) {
        // checks for the existence of a '?' in the passed url:
        var queryAt = url.indexOf('?') + 1;
        /* function exits if:
           1. no 'url' parameter was passed,
           2. no 'param' parameter was passed in, or
           3. the 'queryAt' variable is false, or has a falsey value */
        if ((!url || !param) || !queryAt) {
            return false;
        }
        else {
            /* if the 'param' passed in wasn't found in the 'url' variable,
               the function exits, returning the original url (as no modification
               is required */
            if (url.indexOf(param) == -1) {
                return url;
            }
            else {
                    /* gets the substring of the url from the first
                       character *after* the '?' */
                var all = url.substring(queryAt),
                    // creates an array of the name and value pairs
                    nameValues = all.split('&'),
                    // creating a new array
                    newNameValues = [],
                    parts;
                // iterates through each name-value pair
                for (var i = 0, len = nameValues.length; i < len; i++) {
                    // splits the name-value pair into two parts
                    parts = nameValues[i].split('=');
                    /* if the first part (the 'name' of the param) does not
                       matches what you're looking for then the whole name-value
                       pair is pushed into the 'newNameValues' array */
                    if (parts[0] !== param) {
                        newNameValues.push(nameValues[i]);
                    }
                }
                // returns the reconstructed URL
                return url.substring(0, queryAt) + newNameValues.join('&');
            }
        }
    }
    

    JS Fiddle demo.

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

Sidebar

Related Questions

Possible Duplicate: Get query string values in JavaScript Say if,i've a URL like this
Possible Duplicate: Get query string values in JavaScript I need a function to read
Possible Duplicate: Get query string values in JavaScript If one submits a GET form,
Possible Duplicate: Get query string values in JavaScript I am writing a jQuery function
Possible Duplicate: Get query string values in JavaScript Parse query string in JavaScript http://www.example.org/search?q=example&another=test&again=more
Possible Duplicate: Get query string values in JavaScript how can i get the get
Possible Duplicate: Get entire URL, including query string and anchor I have my url
Possible Duplicates: JavaScript query string get querystring with jQuery Is there an object/method in
Possible Duplicate: Get variable name. javascript “reflection” Is there a way to know the
Possible Duplicate: Get file name from URI string in C# How to extract file

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.