return;
}
log.debug("RegexExtractor processing result");
// Fetch some variables
JMeterVariables vars = context.getVariables();
String refName = getRefName();
int matchNumber = getMatchNumber();
vars.put(refName, getDefaultValue());
Perl5Matcher matcher = (Perl5Matcher) localMatcher.get();
PatternMatcherInput input =
new PatternMatcherInput(
useHeaders() ? context.getPreviousResult().getResponseHeaders()
: new String(context.getPreviousResult().getResponseData())
);
log.debug("Regex = " + getRegex());
try {
Pattern pattern =
patternCache.getPattern(getRegex(), Perl5Compiler.READ_ONLY_MASK);
List matches = new ArrayList();
int x = 0;
boolean done = false;
do
{
if (matcher.contains(input, pattern))
{
log.debug("RegexExtractor: Match found!");
matches.add(matcher.getMatch());
}
else
{
done = true;
}
x++;
}
while (x != matchNumber && !done);
try
{
MatchResult match;
if (matchNumber >= 0){// Original match behaviour
match = getCorrectMatch(matches, matchNumber);
if (match != null)
{
vars.put(refName, generateResult(match));
saveGroups(vars, refName, match);
}
}
else // < 0 means we save all the matches
{
int prevCount = 0;
String prevString=(String)vars.get(refName+"_matchNr");
if (prevString != null)
{
try
{
prevCount = Integer.parseInt(prevString);
}
catch (NumberFormatException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
vars.put(refName+"_matchNr", ""+matches.size());// Save the count
for (int i=1;i<=matches.size();i++) {
match = getCorrectMatch(matches, i);
if (match != null)
{
vars.put(refName+"_"+i, generateResult(match));
saveGroups(vars, refName+"_"+i, match);
}
}
for (int i = matches.size()+1;i<=prevCount;i++)
{
vars.remove(refName+"_"+i);
vars.remove(refName+"_"+i+"_g0");// Remove known groups ...
vars.remove(refName+"_"+i+"_g1");// ...
//TODO remove other groups if present?
}
}
}
catch (RuntimeException e)