【发布时间】:2013-01-28 23:39:51
【问题描述】:
我需要获取特定 jsp 中所有情况的条件变量名称 我正在逐行阅读jsp并搜索特定的模式,比如一行说它检查两种类型的cond,在哪里找到匹配项
<c:if condition="Event ='Confirmation'">
<c:if condition="Event1 = 'Confirmation' or Event2 = 'Action'or Event3 = 'Check'" .....>
Desired Result 是所有 cond 变量的名称 - Event,Event1,Event2,Event3 我写了一个解析器,只满足第一种情况但找不到变量第二种情况的名称。需要一个模式来满足它们。
String stringSearch = "<c:if";
while ((line = bf.readLine()) != null) {
// Increment the count and find the index of the word
lineCount++;
int indexfound = line.indexOf(stringSearch);
if (indexfound > -1) {
Pattern pattern = Pattern
.compile(test=\"([\\!\\(]*)(.*?)([\\=\\)\\s\\.\\>\\[\\(]+?));
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
str = matcher.group(1);
hset.add(str);
counter++;
}
}
【问题讨论】:
-
是的,每次循环迭代都编译模式...