ref
https://stedolan.github.io/jq/manual/
Match from string
Match information is returned in the object
$ echo '"Alice"' | jq 'match("A")' { "offset": 0, "length": 1, "string": "A", "captures": [] }
Output matching character
$ echo '"Alice"' | jq 'match("A").string' "A" $ echo '"Alice"' | jq 'match("(A)")' { "offset": 0, "length": 1, "string": "A", "captures": [ { "offset": 0, "length": 1, "string": "A", "name": null } ] }
To capture
$ echo '“Alice”' | jq 'match(“(A)(l)(i)(c)(e)“)' { “offset”: 0, “length”: 5, “string”: “Alice”, “captures”: [ { “offset”: 0, “length”: 1, “string”: “A”, “name”: null }, { “offset”: 1, “length”: 1, “string”: “l”, “name”: null }, { “offset”: 2, “length”: 1, “string”: “i”, “name”: null }, { “offset”: 3, “length”: 1, “string”: “c”, “name”: null }, { “offset”: 4, “length”: 1, “string”: “e”, “name”: null } ] }
Captured string
$ echo '“Alice”' | jq 'match(“(A)(l)(i)(c)(e)“).captures[].string' “A” “l” “i” “c” “e”
Named Captcha
(An especially meaningless example)
$ echo '“Alice”' | jq 'match(“(?<first_letter>A)(l)(i)(c)(e)“).captures[].name' “first_letter” null null null null
Original by Github issue
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。