in spectator-api/src/main/java/com/netflix/spectator/impl/matcher/PatternUtils.java [337:366]
private static PatternExpr expandLookahead(Matcher matcher) {
List<PatternExpr> exprs = new ArrayList<>();
// 0 - positive matcher to append
// 1 - negative matcher to append
// 2 - remaining matcher to keep processing
Matcher[] results = new Matcher[3];
// Keep processing until no lookaheads remain
removeNextLookahead(matcher, results);
while (results[2] != null) {
if (results[0] != null)
exprs.add(PatternExpr.simple(results[0]));
if (results[1] != null)
exprs.add(PatternExpr.not(PatternExpr.simple(results[1])));
removeNextLookahead(results[2], results);
}
// If the results array is all null, then something was incompatible, return null
// to indicate this regex cannot be simplified
if (results[0] == null && results[1] == null) {
return null;
}
// Add final expression
if (results[0] != null)
exprs.add(PatternExpr.simple(results[0]));
if (results[1] != null)
exprs.add(PatternExpr.not(PatternExpr.simple(results[1])));
return PatternExpr.and(exprs);
}