Closed fbacchella closed 7 years ago
Even simpler case is:
grok.addPattern("WORD", "foo|bar");
grok.addPattern("TEXT", "<< %{WORD}+ >>");
This works for only for namedOnly=false
.
On the other hand:
grok.addPattern("WORD", "(?:foo|bar)");
grok.addPattern("TEXT", "<< %{WORD}+ >>");
... works for both for namedOnly=false
and false
I tried the following code:
And get what I expected:
But if I switch the line
to
The matching failed, and I get:
The matching changed, but I just changed the group wanted. But Look at the regex generated, it goes from
(?<name1>\xEF\xBB\xBF)?
to\xEF\xBB\xBF?
. In the first case, the whole word\xEF\xBB\xBF
is optional. In the second case, only theF
is. Changing the value ofnamedOnly
in compile should not changed the returned values. The pattern in the second case should be(?:((?:\xEF\xBB\xBF)?(?<name2>.*))?)
. The unwanted names should be replaced by?:
, not just dropping the grouping.