[英]finding specific values from file using java
我有一些代碼的JSP文件
<div id="ListDiv" **class="ListDiv"** style="overflow: auto; visibility: visible">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<table **class="List"** cellspacing="0" cellpadding="0">
<tr>
<td class="ColHeader"><%=I18N.get("KEY_LABEL_Sr_No", w_locTextObj)%>.</td>
<td class="ColHeader"><%=I18N.get("KEY_LABEL_Project", w_locTextObj)%></td>
<td class="ColHeader"><%=I18N.get("KEY_LABEL_Status", w_locTextObj)%></td>
<td class="ColHeader"><%=I18N.get("KEY_LABEL_Estimated_Hours", w_locTextObj)%></td>
...
像這樣,我想找到“ class =”字符串並想要它的值"ListDiv" (class="ListDiv",class="List")
多少時間意味着在那里需要用class的值來計數。
1)打開並讀取文件。 我想你可以做到。 請注意,例如,在迭代某些集合時,您的JSP和生成的HTML可能會對這些值具有不同的計數。
2)在這種情況下,您可以嘗試使用諸如class="([^"]*)"
的正則表達式,該正則表達式將在字符串class="
和下一個雙引號作為組1之前返回任何內容。請注意,在Java字符串中您必須在該表達式中轉義雙引號。
例:
Pattern p = Pattern.compile("class=\"([^\"]*)\"");
Matcher m = p.matcher(yourFileContent);
while( m.find() ) {
String classValue = m.group( 1 );
//do whatever you want
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.