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

How to set regexp flags? #3355

Open
radry opened this issue Feb 18, 2024 · 4 comments
Open

How to set regexp flags? #3355

radry opened this issue Feb 18, 2024 · 4 comments
Labels

Comments

@radry
Copy link

radry commented Feb 18, 2024

I need to set the ungreedy flag U but somehow it doesn't work. There are no clear instructions on how to set a flag.

In the Event Formatter Agent there is this example, which I think means A flag?

"regexp": "\A(?<time>\d\d:\d\d [AP]M [A-Z]+)",

However trying to set the U flag (in my regexp, not this example) doesn't work and the result is empty. Even the (?U)foo or (?U:foo) regex modifier isn't accepted and gives an error when trying to save the agent...

I tested the regexp with other tools and it works. Also, without the flag it works but is greedy.

@Unending
Copy link
Collaborator

\A just means the start of the string.

I don't think Ruby regex supports the ungreedy flag, a lot of implementations don't, it's actually strongly discouraged.

Why not just use possessive quantifiers?

@radry
Copy link
Author

radry commented Feb 19, 2024

In the meantime I managed to change the regexp in such a way it works by only matching the correct string, so Ungreedy is not needed anymore.
Regardless it would be good to know how to correctly set flags. The instructions even mention that flags can be set, but now how it's done correctly.

From the Website agents instruction:

Beware that . does not match the newline character (LF) unless the m flag is in effect, and ^/$ basically match every line beginning/end.

@Unending
Copy link
Collaborator

Yeah, but that's just knowing how regex works, not exactly a uniquely Huginn problem.

I'm guessing that line in the agent description was added to reduce support calls. It might be valuable to add that Huginn only supports regex mode modifiers supported by Ruby. Feel free to extend the documentation and make a PR.

@radry
Copy link
Author

radry commented Feb 19, 2024

I'm asking how to set regex flags in huginn. Nothing else :)
Mode modifiers didn't work when I tried it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants