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

  • SEARCH
  • Home
  • 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 9280665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:55:39+00:00 2026-06-18T17:55:39+00:00

I’ve found plenty of articles on StackOverflow that mention fast ways to parse query

  • 0

I’ve found plenty of articles on StackOverflow that mention fast ways to parse query string’s in Javascript, but what I haven’t found is how to handle both & and ; as a delimiter.

Now, I assume, only one of those gets set as the delimiter for the query string. Take for instance, the following query string:

index.php?Param1=value&Param2=value;Param3=value

Which is the delimiter?

  • Is it &, or is it ;?
  • Is it the first recognized delimiting character, or is it & takes precedence over ;?
  • Are both treated as delimiters, and all three parameters from the example parsed?

In Javascript, I have historically been using the following function:

/**
 * Gets the value of a parameter from a URI.
 * @param href The full URI to search. Must at least start with a ? query string delimiter.
 * @param key  The key of the param for which to retrieve the value.
 * @param def  A default value to return in the case that the key cannot be found in the query string.
 * @return The value of the param if the key is found, otherwise returns def.
 */
function getURIParam(href, key, def) {
    if (arguments.length == 2) def = null;

    var qs = href.substring(href.indexOf('?') + 1);
    var s = qs.split('&');
    for (var k in s) {
        var s2 = s[k].split('=');
        if (s2[0] == key)
            return decodeURIComponent(s2[1]);
    }

    return def;
}

That just splits out each key/value pair based on &. It works great, so long as the delimiter is always &. As we know, however, that is not always the case, nor should be enforced, as the RFC allows for ; as well.

So, in order to handle both & and ; as a delimiter, should I first search for an indexOf("&") and if no occurrence is found, set the delimiter to ;?

What is the proper way of parsing a URL based on the rule that the delimiter can be either & or ;?

Here is the W3C Recommendation on server being able to handle both & and ;.

We recommend that HTTP server implementors, and in particular, CGI
implementors support the use of “;” in place of “&” to save authors
the trouble of escaping “&” characters in this manner.

Here is RFC 1738 which defines the URI.

  • 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-18T17:55:40+00:00Added an answer on June 18, 2026 at 5:55 pm

    You can use reg ex to split on two delimiters.

    var s = qs.split(/[&;]/)
    

    This will handle strings with both & and ;

    Edit:

    here is a post to split on one or the other given the first occurence of the character. Hopefully the URL contains the semicolon first but it might be safer to check for any occurrence of ; and just using that as the delimiter if present.

    According to RFC3986 it is up to the scheme implementor to decide on how the usage of the URI reserved characters is to be used. Also According to RFC 1738, semi-colon is a reserved character in the search part of a URI, and as such, if present, is treated as a delimiter, unless encoded.The W3C recommends that server implementers allow both to allow developers to not have to escape the ampersand, therefore one or the other should be used.

    I would intrepid your example of

    index.php?Param1=value&Param2=value;Param3=value
    

    as

    ["Param1=value&Param2=value","Param3=value"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text

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.