Skip to content
Permalink
Browse files
Use Pattern cache from JMeterUtils and extract constant Pattern
  • Loading branch information
FSchumacher committed Mar 5, 2022
1 parent d73d65f commit 65e6afa9d195615e0e0c1abe13ec6b315f7c9efe
Showing 1 changed file with 4 additions and 2 deletions.
@@ -60,6 +60,8 @@ public class RegexFunction extends AbstractFunction {

private static final List<String> desc = new ArrayList<>();

private static final java.util.regex.Pattern FIRST_ELEMENT_PATTERN = java.util.regex.Pattern.compile("^\\$\\d+\\$");

private static final String TEMPLATE_PATTERN = "\\$(\\d+)\\$"; //$NON-NLS-1$
/** initialised to the regex \$(\d+)\$ */
private final Pattern templatePattern;
@@ -212,7 +214,7 @@ private String getResultWithJavaRegex(String valueIndex, String defaultValue, St

private java.util.regex.Pattern generateJavaPattern() throws InvalidVariableException {
try {
return java.util.regex.Pattern.compile(((CompoundVariable) values[0]).execute());
return JMeterUtils.compilePattern(((CompoundVariable) values[0]).execute());

} catch (PatternSyntaxException e) {
log.error("Malformed regex pattern:{}", values[0], e);
@@ -423,7 +425,7 @@ private Object[] generateTemplateWithOroRegex(String rawTemplate) {

private boolean isFirstElementGroup(String rawData) {
if (useJavaRegex) {
return java.util.regex.Pattern.compile("^\\$\\d+\\$").matcher(rawData).find();
return FIRST_ELEMENT_PATTERN.matcher(rawData).find();
} else {
Pattern pattern = JMeterUtils.getPatternCache().getPattern("^\\$\\d+\\$", //$NON-NLS-1$
Perl5Compiler.READ_ONLY_MASK);

0 comments on commit 65e6afa

Please sign in to comment.