Regex lookahead in painless

Is it possible to use regex with lookahead in Painless?
I want to match a pattern in a string starting with a certain expression and ending before a certain expression.

I believe Painless supports what Java supports, which includes lookaheads. For example,

"look ahead operator" =~ /look (?=ahead).+/

is a match in Painless.

You do need to be aware of the Elasticsearch settings that, by default, limit regex complexity: Elasticsearch regex circuit breaker settings.

Yes it works
But I struggled with the code.

It goes like this:


 def mm = /request=.*(?=response)/.matcher(message);
 if (mm.find()) {
            ctx._source['mm'] = mm.group(0);
 }

This matches "request.*" until the string "response" is found.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.