-
I need to process JSON files that contain regular expressions (regexes). I plan to use jq to make changes to the files and I would also like to validate the regexes in them. I think the simplest way to do that would be using some function in jq to compile the regexes. For my purposes, if the regexes compile successfully, I'm comfortable with considering them valid. If the compilation fails, they are invalid. The problem is I don't see a function for compiling regexes in jq. I know jq can use regexes for matching input or transforming it, but I don't see how I can compile one received as input. Suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Using the input as the regex filter argument can validate the regexes. $ echo '".*" "[a]" "*" "["' | jq '. as $pattern | try ("" | test($pattern) | true) catch (startswith("Regex failure") | not)'
true
true
false
false |
Beta Was this translation helpful? Give feedback.
Using the input as the regex filter argument can validate the regexes.