Hey there,
I'm trying to use jq's regex to sub semver, but I cannot escape the dot, as it throws a compiler error.
echo "{\"VERSION\": \"0.2.1-alpha+abxc23\"}" |\
jq '.VERSION | sub("(?<vers>[0-9]+\.[0-9]+\.[0-9]+).*"; (.vers))'
Should give me the version, but fails with a compilation error.
$ echo "{\"VERSION\": \"0.2.1-alpha+abxc23\"}" |\
jq '.VERSION | sub("(?<vers>[0-9]+\\.[0-9]+\\.[0-9]+).*"; .vers)'
"0.2.1"
As the documentation says, the arguments to regex filters must be valid jq strings, which basically means valid JSON strings but allowing for interpolation. In other words, you need to escape the . with two backslashes.
Ah ok. I tried that, but I thought I had to escape the backslash as well, trying only with ".", and not just ".". Thanks for clarifying.
Most helpful comment
As the documentation says, the arguments to regex filters must be valid jq strings, which basically means valid JSON strings but allowing for interpolation. In other words, you need to escape the . with two backslashes.