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

scan("(a)(b)") returning an array is not documented #3086

Open
emanuele6 opened this issue Mar 29, 2024 · 0 comments
Open

scan("(a)(b)") returning an array is not documented #3086

emanuele6 opened this issue Mar 29, 2024 · 0 comments
Labels

Comments

@emanuele6
Copy link
Member

Describe the bug
If the regular expression of scan/1/scan/2 contains a capture group, arrays contains the values of the capture groups are returned instead of strings that are the full match of the regular expression.

I use this feature all the time, and I have just noticed it is not documented!

scan(regex), scan(regex; flags)
     Emit a stream of the non-overlapping substrings of the input that match
     the regex in accordance with the flags, if any have been specified. If
     there is no match, the stream is empty. To capture all the matches for
     each input string, use the idiom [ expr ], e.g. [ scan(regex) ].

         jq ´scan("c")´
            "abcdefabc"
         => "c", "c"

To Reproduce

$ jq -cn '"foo bar xzbox" | scan(".b.")'
" ba"
"zbo"
$ jq -cn '"foo bar xzbox" | scan("(.)b(.)")'
[" ","a"]
["z","o"]

Expected behavior
The feature should be documented.

Environment (please complete the following information):

  • OS and Version: Arch Linux
  • jq version: 1.7.1

Additional context
This feature has been supported by jq for many years, and it also works in gojq.

@emanuele6 emanuele6 added the docs label Mar 29, 2024
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

1 participant