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
Proposal: regex.replace(search, pattern, value) #5162
Comments
Thanks for suggesting that, @datfinesoul 👍 Would you like to take a shot at an implementation? :) |
@anderseknert My golang skills are practically non-existent at the moment so that might be somewhat of a problem, but if no one has time to tackle this in the coming months, I'll give it a shot as I improve. |
Cool! I've labeled it as a good first issue, so it's not unthinkable that someone else wants to give it a shot. But if that happens, we'll have other issues for you if you're up for it :) |
wouldn't the following work for this case? afaik, there's already one builtin replace method but probably it doesn't support general regex syntax preferred := { x |
some part in input.session.teams
x := strings.replace_n({" ": "-"}, part)
} |
@boranx yeah, for simple cases you can probably achieve what you need with a combination of the current builtin functions, iteration and some other constructs. Having the option to do replace on patterns rather than values seems like a good addition nonetheless :) |
Hey folks, I wanted to give it a shot and created a small PR to implement the proposal |
Awesome, @boranx 👏 😃 |
What is the underlying problem you're trying to solve?
See the un-commented parts of the example
https://play.openpolicyagent.org/p/aApnhKICLK
We were asking around about ways to do some more complex string manipulation, in this case taking the "friendly" github usernames, and converting them into their ID type format. The best thing we could find after asking on the OPA slack was the solution in this example.
Describe the ideal solution
See the example, the commented "preferred" block
https://play.openpolicyagent.org/p/aApnhKICLK
Describe a "Good Enough" solution
I'm not sure I can think of a different option. Since rego already has support for regex matches my assumption is that the above option might be possible.
Additional Context
The text was updated successfully, but these errors were encountered: