【发布时间】:2011-09-02 08:06:40
【问题描述】:
在this question 之后,它只给了我第一场比赛。我想将所有匹配项放入一个字符串或字符串数组中
这是我需要从中提取所有Category 的输出部分
<Trace Enabled="false">
<ActiveCategories>
<Category>ENVIRONMENT</Category>
<Category>EXEC</Category>
<Category>EXTERNALS</Category>
<Category>FILESYSTEM</Category>
<Category>INPUT_DOC</Category>
<Category>INTERFACES</Category>
<Category>NETWORKING</Category>
<Category>OUTPUT_DOC</Category>
<Category>PREPROCESSOR_INPUT</Category>
<Category>REQUEST</Category>
<Category>SYSTEMRESOURCES</Category>
<Category>VIEWIO</Category>
<Category>ALL</Category>
</ActiveCategories>
<SeverityLevel>ERROR</SeverityLevel>
<MessageInfo>
<ProcessAndThreadIds>true</ProcessAndThreadIds>
<TimeStamp>true</TimeStamp>
</MessageInfo>
<TraceFile>
<FileName>CMDS_log.txt</FileName>
<MaxFileSize>1000000</MaxFileSize>
<RecyclingMethod>Restart</RecyclingMethod>
</TraceFile>
</Trace>
现在通过下面的代码我只能获取ENVIRONMENT,我需要获取所有Category的值
def regexFinder(String myInput,String myRegex)
{
String ResultString
Pattern regex
Matcher regexMatcher
regex = Pattern.compile(myRegex, Pattern.DOTALL);
regexMatcher = regex.matcher(myInput);
if (regexMatcher.find()) {
ResultString = regexMatcher.group();
}
}
tempResultString=regexFinder(ResultString,"(?<=<Category>)(?:(?!</Category>).)*")
csm.cmengine_category(tempResultString)
{ "${rs}" }
【问题讨论】: