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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:32:21+00:00 2026-06-13T10:32:21+00:00

I’ve been at this for hours, and I’m hitting a dead end. I’ve read

  • 0

I’ve been at this for hours, and I’m hitting a dead end. I’ve read up on Regular Expressions all over the place, but I’m still having trouble matching on anything more complex than basic patterns.

So, my problem is this:

I need to split an “&” delimited to string into a list of objects, but I need to account for the values containing the ampersand as well.

Please let me know if you can provide any help.

var subjectA = 'myTestKey=this is my test data & such&myOtherKey=this is the other value';

Update:

Alright, to begin with, thanks for the awesome, thoughtful responses. To give a little background on why I’m doing this, it’s to create a cookie utility in JavaScript that is a little more intelligent and supports keys ala ASP.

With that being said, I’m finding that the following RegExp /([^&=\s]+)=(([^&]*)(&[^&=\s]*)*)(&|$)/g does 99% of what I need it to. I changed the RegExp suggested by the contributors below to also ignore empty spaces. This allowed me to turn the string above into the following collection:

[
    [myTestKey, this is my test data & such],
    [myOtherKey, this is the other value]]
]

It even works in some more extreme examples, allowing me to turn a string like:

var subjectB = 'thisstuff===myv=alue me==& other things=&thatstuff=my other value too';

Into:

[
    [thisstuff, ==myv=alue me==& other things=],
    [thatstuff, my other value too]
]

However, when you take a string like:

var subjectC = 'me===regexs are hard for &me&you=&you=nah, not really you\'re just a n00b';

Everything gets out of whack again. I understand why this is happening as a result of the regular expression above (kudos for a very awesome explanation), but I’m (obviously) not comfortable enough with regular expressions to figure out a work around.

As far as importance goes, I need this cookie utility to be able to read and write cookies that can be understood by ASP and ASP.NET & vice versa. From playing with the example above, I’m thinking that we’ve taken it as far as we can, but if I’m wrong, any additional input would be greatly appreciated.

tl;dr – Almost there, but is it possible to account for outliers like subjectC?

var subjectC = 'me===regexs are hard for &me&you=&you=nah, not really you\'re just a n00b';

Actual ouput:

[
    [me, ==regexs are hard for &me],
    [you, ],
    [you, nah, not really you\'re just a n00b]
]

Versus expected output:

[
    [me, ==regexs are hard for &me&you=],
    [you, nah, not really you\'re just a n00b]
]

Thanks again for all of your help. Also, I’m actually getting better with RegExp… Crazy.

  • 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-13T10:32:23+00:00Added an answer on June 13, 2026 at 10:32 am

    If your keys cannot contain ampersands, then it’s possible:

    var myregexp = /([^&=]+)=(.*?)(?=&[^&=]+=|$)/g;
    var match = myregexp.exec(subject);
    while (match != null) {
        key = match[1];
        value = match[2];
        // Do something with key and value
        match = myregexp.exec(subject);
    }
    

    Explanation:

    (        # Match and capture in group number 1:
     [^&=]+  # One or more characters except ampersands or equals signs
    )        # End of group 1
    =        # Match an equals sign
    (        # Match and capture in group number 2:
     .*?     # Any number of characters (as few as possible)
    )        # End of group 2
    (?=      # Assert that the following can be matched here:
     &       # Either an ampersand,
     [^&=]+  # followed by a key (as above),
     =       # followed by an equals sign
    |        # or
     $       # the end of the string.
    )        # End of lookahead.
    

    This may not be the most efficient way to do this (because of the lookahead assertion that needs to be checked several times during each match), but it’s rather straightforward.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.