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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:50:08+00:00 2026-05-16T17:50:08+00:00

I have the following possible strings that I need to turn into arrays so

  • 0

I have the following possible strings that I need to turn into arrays so I can feed them into an html generator. I am not staring with html or XML, I am trying to create a shorthand that will allow me to populate my html objects much simpler and faster with more readable code.

id='moo'
id = "foo" type= doo    value ='do\"o'
on_click='monkeys("bobo")'

I need to pull out the attribs and their corresponding values. These attrib strings are not associated with an html or xml tag. And I would like to do it with 1 to 3 regular expressions

  • The value may be encapsulated by either single or double quotes
  • If the value is encapsulated by quotes it may also contain whitespace, quotes different from encapsulating quotes or escaped quotes that are same as the encapsulating quotes.
  • There may or may not be whitespaces between the attrib and =, and the = and value.

The eventual results should look like:

array(1) {
  [id] => moo
}
array(3) {
  [id] => foo
  [type] => doo
  [value] => do"o
}
array(1) {
  [on_click] => monkeys("bobo")
}

but if it turns out like:

array(2) {
  [0] => id
  [1] => moo
}
array(6) {
  [0] => id
  [1] => moo
  [2] => class
  [3] => foo
  [4] => value
  [5] => do"o
}

array(2) {
  [0] => on_click
  [1] => monkeys("bobo")
}

I can re-arrange it from there.

Some previous regexes I have tried to use and their issues:

  • /[\s]+/ – Return attrib/value pairs only if there was no whitespace around the =
  • /(?<==)(\".*\"|'.*'|.*)$/ – Returns value including the encapsulating quotes. It does ignore escaped quotes within the value though
  • /^[^=]*/ – Returns the attribute just fine. regardless of whitespace between attrib and =
  • 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-05-16T17:50:09+00:00Added an answer on May 16, 2026 at 5:50 pm

    Any particular reason you want to use regex specifically here? Seems like a token-based parser might work better for you, as you need to keep more state than is comfortable to do in a regex.

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

Sidebar

Related Questions

I need to build ONE regular expression that can detect ALL the following strings
I have the following xml that I need to deserialise to an object: <animals>
I have a list of strings that I need to use to create the
I have the following String that I need to parse. I am looking for
I need a starting point to make the following possible. I have a Main
I have a list of strings (a List<String> ) that can have anywhere from
I have a text file in the assets folder that I need to turn
Is it possible to pass *args to string.format? I have the following function: @classmethod
Is the following at all possible in c#? I have the following but the
Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in

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.