curl -H "API_key:[API_PASSWORD]" http://API.wordnik.com/v4/word.Json/button/pronunciations?sourceDictionary=macmillan&typeFormat=IPA&useCanonical=false
收益:
[{"ID":0,"seq":0,"raw":"ˈbʌt(ə)n","rawType":"IPA"},{"ID":0,"rawType":"IPA"}]
我正试图提取“bʌt(ə)n”元素.
虽然我不熟悉正则表达式,但我认为我应该使用这个字符串替换:
/.*"(.*)",/
我正在尝试运行以下命令,但它似乎不起作用:
curl -H "API_key:[API_KEY]" http://API.wordnik.com/v4/word.Json/button/pronunciations?sourceDictionary=macmillan&typeFormat=IPA&useCanonical=false | sed /.*"(.*)",/
我确定有一些事情我做错了,经过几个小时的搜索和阅读正则表达式和bash我没有选择.
我不需要使用sed,我只是在bash命令行中寻找一种快速的方法,这样我就可以在mac上的textexpander脚本中实现它.
解决方法 使用STRING:REGEXP从Json字符串中提取值:string=$(curl -H "API_key:[API_PASSWORD]" http://API.wordnik.com/v4/word.Json/button/pronunciations?sourceDictionary=macmillan&typeFormat=IPA&useCanonical=false)raw=$(expr "$string" : '.*"raw":"\([^"]*\)"')echo $raw
见man expr:
STRING : REGEXP anchored pattern match of REGEXP in STRING Pattern matches return the string matched between \( and \) or null总结
以上是内存溢出为你收集整理的regex – 如何使用curl和sed从短json查询中提取单个元素全部内容,希望文章能够帮你解决regex – 如何使用curl和sed从短json查询中提取单个元素所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)