Example of matching with regular expression from #JSON by #Jq command
<h1> ref </h1><p> https://stedolan.github.io/jq/manual/ </p><h1> Match from string </h1><p> Match information is returned in the object </p><pre> <code>$ echo '"Alice"' | jq 'match("A")' { "offset": 0, "length": 1, "string": "A", "captures": [] }</code> </pre><h1> Output matching character </h1><pre> <code>$ 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 } ] }</code> </pre><h1> To capture </h1><pre> <code>$ 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 } ] }</code> </pre><h1> Captured string </h1><pre> <code>$ echo '“Alice”' | jq 'match(“(A)(l)(i)(c)(e)“).captures[].string' “A” “l” “i” “c” “e”</code> </pre><h1> Named Captcha </h1><p> (An especially meaningless example) </p><pre> <code>$ echo '“Alice”' | jq 'match(“(?<first_letter>A)(l)(i)(c)(e)“).captures[].name' “first_letter” null null null null</code> </pre>
Original by Github issue
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
公開日時
2019-04-20
Discussion