0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

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

Last updated at Posted at 2019-04-20

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オープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?