🖥

Example of matching with regular expression from #JSON by #Jq command

2019/04/20に公開

<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

https://github.com/YumaInaura/YumaInaura/issues/1341

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-04-20

Discussion