Skip to content

[Enhancement] Error handling for unsupported characters in java regex library #4467

Closed

Description

@RyanL1997

Description

Currently for extraction commands like rex and parse which are replying on the java regex library, once the user specified the named capture groups with some unsupported illegal characters lik _, -. etc. It will return a 400 as the request response with a very unclear error message. For example:

# rex command with illegal character of -
curl -X POST "localhost:9200/_plugins/_ppl" \
    -H "Content-Type: application/json" \
    -d '{
      "query": "source=accounts | rex field=email \".+@(?<domain-name>.+)\" | fields email, domain-name"
    }'
{
  "error": {
    "reason": "Invalid Query",
    "details": "Rex pattern must contain at least one named capture group",
    "type": "IllegalArgumentException"
  },
  "status": 400
}

In the above it only states that the name capture itself is invalid but no description of the actual reason.

Expected Behavior

Having a validation logic to make sure the named captured group follows the supported java regex pattern:

  • Valid Characters:
    • Must start with: Letter (a-z, A-Z)
    • Can contain: Letters (a-z, A-Z) and digits (0-9)

Having a clear error msg to call out the following invalid characters in the user provided pattern:

  • Invalid Characters (will cause PatternSyntaxException):
    • Underscore (_) - This is what we're handling with our validation
    • Hyphen/Dash (-) - This is what you tested with curl
    • Period/Dot (.)
    • Space ( )
    • Special characters (@, #, $, %, ^, &, *, etc.)
    • Unicode characters beyond ASCII
    • Cannot start with digit (0-9)

Exit Criteria

  • Leverage the existing regex util to make sure all the extraction related commands are covered by the fix / enhancement
  • Add proper testing for parse / rex to validate the new behavior
  • Update the cmd doc if needed

Reference

Activity

  1. self-assigned this
    on Oct 9, 2025
  2. added
    enhancement
    PPL
    calcite
    on Oct 9, 2025
  3. RyanL1997 commented on Oct 9, 2025

    @RyanL1997
    CollaboratorAuthor

    Java Regex Named Group Character Rules

    According to Java's Pattern class documentation, named capture groups follow these rules:

    Valid Characters:

    • Must start with: Letter (a-z, A-Z)
    • Can contain: Letters (a-z, A-Z) and digits (0-9)

    Invalid Characters (will cause PatternSyntaxException):

    • Underscore (_) - This is what we're handling with our validation
    • Hyphen/Dash (-) - This is what you tested with curl
    • Period/Dot (.)
    • Space ( )
    • Special characters (@, #, $, %, ^, &, *, etc.)
    • Unicode characters beyond ASCII
    • Cannot start with digit (0-9)

    Java Documentation:

    The official Java documentation for this is in:

    • Java Pattern class: java.util.regex.Pattern
    • Specific section: "Named-capturing group" in the Pattern syntax documentation
    • Rule: Named groups use the syntax (?X) where name must be a valid Java identifier but with more restrictions

    The exact Java rule is:

      // From Java's Pattern class source code:
      // Named group name must match: [a-zA-Z][a-zA-Z0-9]*
    

    Quick Test Examples:

    # These will FAIL in Java regex:
    (?<domain_name>...)  # underscore
    (?<domain-name>...)  # hyphen  
    (?<domain.name>...)  # dot
    (?<domain name>...)  # space
    (?<@domain>...)      # special char
    (?<1domain>...)      # starts with digit
    
    # These will WORK in Java regex:
    (?<domain>...)       # letters only
    (?<domainName>...)   # camelCase
    (?<domain1>...)      # letters + numbers
    (?<DOMAIN>...)       # uppercase
    
  4. moved this from Not Started to Done in PPL Trackeron Oct 14, 2025
  5. added
    error-experience
    on Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

PPLcalciteenhancementerror-experience

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions