I need a Java Pattern to fetch all the attributes of an HTML element which would be passed as String. Initially, I had Used to split them using the following Pattern
private static Pattern scriptletvalue1 = Pattern.compile("value=\"([^\"]*)\"");
private static Pattern scriptletvalue2 = Pattern.compile("value='([^']*)'");
private static Pattern scriptletId1 = Pattern.compile("id=\"([^\"]*)\"");
private static Pattern scriptletId2 = Pattern.compile("id='([^\']*)'");
and so on for all the attributes, This would work fine until there are no double quotes inside the attribute values. But considering a scriptlet inside the attribute value which would be calling functions might have parameters with double quotes and that is where the above-mentioned patterns fail.
So for an attribute
<div value="<%=AnyText%>"></div>
The first pattern would give me <%=AnyText%>
But when I use the same pattern for
<div value="<%=myFunction.getValue("some Key")%>"></div>
the pattern would return <%=myFunction.getValue(
instead of <%=myFunction.getValue("some Key")%>
How to fix it?