Skip to content

Matched json is blank in case any of one regex out multiple does not match #76

Open

Description

@sudhirkumar1980

java grok is return matched json as blank when one regex out of multple does not match.
Example
grok = Grok.create("patterns/patterns");
grok.compile("%{NUMBER:hits} %{USER:word}");
String s = "234\n";
Match gm = grok.match(s);
gm.captures();
System.out.println(gm.toJson());

in this case only %{NUMBER:hits} matches and not %{USER:word}. I expect java grok to return json {"hits":234} but it is returning {}.

Activity

  1. retoo commented on Mar 6, 2018

    @retoo
    Contributor

    try:

     grok.compile("%{NUMBER:hits}(?: %{USER:word})?");
    

    if tell grok to match "numer word" then it will expect that there's a number and then a word. The word is not optional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions