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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:09:52+00:00 2026-06-14T07:09:52+00:00

I have a small piece of code that needs to split a string into

  • 0

I have a small piece of code that needs to split a string into a javascript object.

The resulting object need to look something like this:

var myObject = {
valueOne: value,
valueTwo: value,
arrayOfValues: [values] 
}

The strings that need to be converted come in two different formats. Those formats look like:

1) "MyValues are ('1','2','3')"
–this would be translated into :

var myObject = {
valueOne: myValues,
valueTwo: are,
arrayOfValues: [1,2,3] 
}

or
2) "MyValue="1""
–this would be translated into :

var myObject = {
valueOne: myValue,
valueTwo: =,
arrayOfValues: [1] 
}

I know I can split this string like so:

var arr[] = myString.split(" ");

But deciding which splitter to use based on the makeup of the string, then converting it into a javascript object is a world unknown to me.

Thanks for your help.

EDIT — I made a small mistake with example number two

I updated it so that it’s correct. — The string I’m receiving is in the format of:

`"MyValue="1""`

samy-delux, thanks for your help! That works great, but the change to this second string breaks your example. (I’m sorry, I mistyped the format of the string.)

I’m doing my best to learn about regular expressions. But don’t know enough yet to solve this problem.

  • 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-14T07:09:54+00:00Added an answer on June 14, 2026 at 7:09 am

    Here you go ( http://jsfiddle.net/VBmb8/ ):

    function parse(str) {
        var match = str.match(/(\w+)\s?([\w=]+)\s?\('(.+)'\)/);
    
        return {
            valueOne: match[1],
            valueTwo: match[2],
            arrayOfValues: match[3].split("','")
        };
    }
    

    * After your edit *

    http://jsfiddle.net/VBmb8/2/

    function parse(str) {
        var match = str.match(/(\w+)\s?([\w=]+)\s?\(?['"](.+)['"]\)?/);
    
        return {
            valueOne: match[1],
            valueTwo: match[2],
            arrayOfValues: match[3].split("','")
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small piece of code that works as a plugin for a
I have this small piece of code that basically takes a list and runs
I have a small piece of code that I use to keep track of
I have just written a small piece of code and it struck me that
I have a small piece of code that depends on many static libraries (a_1-a_n).
I have a small piece of code that should compile and allow the user
I have a small pyopengl piece of code that uses shaders. I get the
I have a small piece of code that requires to read 4-bit values bitpacked
I have a small piece of code that produce PrimeFaces dropdown List p:selectOneMenu ,
I have this small piece of code that simply pulls in a news release

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.