Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regexp literal escaping #2061

Closed
cyriltovena opened this issue May 11, 2020 · 4 comments
Closed

Regexp literal escaping #2061

cyriltovena opened this issue May 11, 2020 · 4 comments
Labels
component/loki keepalive An issue or PR that will be kept alive and never marked as stale. type/enhancement Something existing could be improved

Comments

@cyriltovena
Copy link
Contributor

cyriltovena commented May 11, 2020

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

For filter expression and soon to come extract expression, regexp can be difficult to write. Because of the quoted string {app="foo"} |= "\\w+" the normal string escape rules (preceding special characters with \ when included in a string) are necessary. This causes regular expression to be converted.

Describe the solution you'd like
Javascript has 2 ways of declaring regexp see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

The literal notation's parameters are enclosed between slashes and do not use quotation marks.
The constructor function's parameters are not enclosed between slashes but do use quotation marks.

Example:

let re = /\w+/
let re = new RegExp('\\w+')

As you can see the first one doesn't need escape.

So my suggestion is to support the two syntax:

  • {app="foo"} |= "\\w+"
  • {app="foo"} |= /\w+/

Describe alternatives you've considered
Do nothing and live with it, personally sometimes it a pain to prepare a regex in an online editor and then have to fiddle with it to make sure everything is escaped correctly.

Additional context
Here is a example that was difficult to build for this reason:
image

/cc @owen-d @slim-bean if we have consensus I could work on that.

@cyriltovena cyriltovena added component/loki type/enhancement Something existing could be improved keepalive An issue or PR that will be kept alive and never marked as stale. labels May 11, 2020
@cyriltovena cyriltovena changed the title Regexp literal escape Regexp literal escaping May 11, 2020
@owen-d
Copy link
Member

owen-d commented May 12, 2020

lgtm - go for it!

@slim-bean
Copy link
Collaborator

love it!

@cyriltovena
Copy link
Contributor Author

I don't think we can support this with the current lexer. We might need to build our own.

/cc @owen-d

@cyriltovena
Copy link
Contributor Author

Fixed by #2095

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/loki keepalive An issue or PR that will be kept alive and never marked as stale. type/enhancement Something existing could be improved
Projects
None yet
Development

No branches or pull requests

3 participants