router icon indicating copy to clipboard operation
router copied to clipboard

Regex Support in Rhai

Open lleadbet opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe.

Working in Rhai is typically preferred for performance reasons when config can't suffice. For some customers, there is a need to do complex lookups on string values to ensure they match a specific format (and optionally retrieve matching values).

As a concrete example, if a customer needed to check against a User-Agent value and apply a different header based on that value, regex could be well-suited for this need since simple string lookups may not suffice when working with the format.

While it may work for some use-cases, and might be able to work for others, it creates a lot of gnarly code that regex is uniquely suited for.

Additionally, pattern matching a header value can incredibly powerful.

Describe the solution you'd like

Support for Regex in Rhai, ideally:

  • A method to generate a new "regex" type from a user-provided regex string
  • From that regex type, the ability to do both non-matching and matching group lookups

Describe alternatives you've considered

As noted above, using substring lookups.

lleadbet avatar Jun 23 '23 21:06 lleadbet

Just adding my support for this, would be nice to be able to do some pattern matching against the query to support some use cases like looking for a query name by a specific pattern. (ie, same as the operation name).

tjsiron avatar Nov 17 '23 20:11 tjsiron

We have a use case where we need to pattern match against header names in a Rhai script and regex would greatly simplify this

danpayne17 avatar Apr 15 '24 15:04 danpayne17