I found this useful regex code here, looking at the attributes of HTML tags:
(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?
It works great, but I miss one key element that I need. Some attributes are event triggers that have embedded Javascript code in them as follows:
onclick="doSomething(this, 'foo', 'bar');return false;"
Or:
onclick='doSomething(this, "foo", "bar");return false;'
I can’t figure out how to get the original expression so as not to read the quotes from JS (single or double), while it is nested inside a set of quotes containing the attribute value.
I MUST add that this is not used to parse the entire HTML document. It was used as an argument in the old array-to-select function, which I updated. One argument is a tag that can add additional HTML attributes to the form element.
I made an improved function and condemn the old one ... but in case there is a call to an old function somewhere in the code, I need to parse it into a new array format. Example:
function create_form_element($array, $type, $selected="", $append_att="") { ... }
create_form_element($array, SELECT, $selected_value, "onchange=\"something(this, '444');\"");
The new version accepts an array of attr => value pairs to create additional tags.
create_select($array, $selected_value, array('style' => 'width:250px;', 'onchange' => "doSomething('foo', 'bar')"));
, OLD , $append_att , regex HTML. , , .