Question
From your encrypted description assuming I have deciphered it correctly !
Looks to me that your jsp page contains following line
<img src="a.jpeg" class="<%=w_canEdit?"IconSpacing":"IconDisable"%>"/>
And your regular expression matches <%=w_canEdit?\
@Test
public void testRegex() {
Pattern p = Pattern.compile("class=\"([^\"]*)\"");
Set set = new HashSet();
//<img class="<%=w_canEdit?"IconSpacing":"IconDisable"%>" src="a.jpeg"/>
String str="<img src=\"a.jpeg\" class=\"<%=w_canEdit?\"IconSpacing\":\"IconDisable\"%>\"/>";
System.out.println(str);
Matcher m = p.matcher(str);
while (m.find())
{
String classValue = m.group(1);
set.add(classValue);
}
System.out.println("Result:");
System.out.println(set);
}
Output
Input:
<img src="a.jpeg" class="<%=w_canEdit?"IconSpacing":"IconDisable"%>"/>
Result:
[<%=w_canEdit?]
what you expect in the result
[IconSpacing,IconDisable]
Answer
Short answer :
you can not do it with regex
Long answer :
you can not do it with regex, even if with lookahead hacks you might be able to resolve it as <%=w_canEdit?"IconSpacing":"IconDisable"%>
like for ex using following pattern
Pattern p = Pattern.compile("class=\"(<%=(.(?<!%>\"))*)\"");
// [<%=w_canEdit?"IconSpacing":"IconDisable"%>]
you will still never be able to identify runtime value of a class
[as either IconSpacing
or IconDisable
] by parsing jsp file anyways.
Easiest way to do this is to to do it manually
grep class= *.jsp
- identify css classes that have jsp scriptlets in them
- extract the required details from the result
If you can raise a separate Question with exact details of your requirement people here would be definitely happy to help
Also See this post RegEx match open tags except XHTML self-contained tags to understand why using regex to parse html/jsp pages is not that great idea !