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

Escaping dot in regex does not work #1250

Closed
Tritlo opened this issue Oct 7, 2016 · 2 comments
Closed

Escaping dot in regex does not work #1250

Tritlo opened this issue Oct 7, 2016 · 2 comments

Comments

@Tritlo
Copy link

Tritlo commented Oct 7, 2016

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.

@pkoppstein
Copy link
Contributor

$ 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.

@Tritlo
Copy link
Author

Tritlo commented Oct 9, 2016

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.

@Tritlo Tritlo closed this as completed Oct 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants