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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:58:24+00:00 2026-05-10T22:58:24+00:00

What’s the best way to extract the key and value from a string like

  • 0

What’s the best way to extract the key and value from a string like this:

var myString = 'A1234=B1234'; 

I originally had something like this:

myString.split('='); 

And that works fine, BUT an equal (=) sign could be used as a key or value within the string plus the string could have quotes, like this:

var myString = ''A123=1=2=3=4'='B1234''; 

The string could also only have one pair of quotes and spaces:

var myString = ' 'A123=1=2=3=4' = B1234 '; 

I’m not very good at regular expressions but I’m guessing that’s the way forward?

What I want to end up with is two variables, key and value, in the case above, the key variable would end up being A123=1=2=3=4 and the value variable would be B1234.

If there is no value present, for example if this were the original string:

var myString = 'A1234'; 

Then I would want the key variable to be ‘A1234’ and for the value variable to be null or false – or something I can test against.

Any help is appreciated.

  • 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. 2026-05-10T22:58:25+00:00Added an answer on May 10, 2026 at 10:58 pm

    What I’ve tended to do in config files is ensure that there’s no possibility that the separator character can get into either the key or value.

    Sometimes that’s easy if you can just say ‘no ‘=’ characters allowed’ but I’ve had to resort to encoding those characters in some places.

    I generally hex them up so that if you wanted a ‘=’ character, you would have to put in %3d (and %25 for the ‘%’ character so you don’t think it’s a hex-starter character). You can also use %xx for any character but it’s only required for those two.

    That way you can check the line to ensure it has one and only one ‘=’ character then post-process the key and value to turn the hex’ed characters back into real ones.

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have text I am displaying in SIlverlight that is coming from a CMS
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a JSP page retrieving data and when single or double quotes are

Explore

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.