Note that there are some explanatory texts on larger screens.

plurals
  1. POregex to extract names and values of attributes
    primarykey
    data
    text
    <p>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.</p> <pre> id='moo' id = "foo" type= doo value ='do\"o' on_click='monkeys("bobo")' </pre> <p>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 <strong>regular expressions</strong></p> <ul> <li>The value may be encapsulated by either single or double quotes</li> <li>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.</li> <li>There may or may not be whitespaces between the attrib and =, and the = and value.</li> </ul> <p>The eventual results should look like:</p> <pre> array(1) { [id] => moo } array(3) { [id] => foo [type] => doo [value] => do"o } array(1) { [on_click] => monkeys("bobo") } </pre> <p>but if it turns out like:</p> <pre> 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") } </pre> <p>I can re-arrange it from there.</p> <p>Some previous regexes I have tried to use and their issues:</p> <ul> <li><code>/[\s]+/</code> - Return attrib/value pairs only if there was no whitespace around the =</li> <li><code>/(?&lt;==)(\".*\"|'.*'|.*)$/</code> - Returns value including the encapsulating quotes. It does ignore escaped quotes within the value though</li> <li><code>/^[^=]*/</code> - Returns the attribute just fine. regardless of whitespace between attrib and =</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload