【发布时间】:2015-08-13 14:32:32
【问题描述】:
我对正则表达式几乎是新手。
我正在使用 jayway 和 ruby regexp 编写 JsonPath 表达式 我想通过仅匹配图书作者属性的前 2 个字母来查找节点
实际表达方式
$..book[?(@.author =~ /\A.{0}(Ni).*/)]
找到我需要的东西
[
{
"category" : "reference",
"author" : "Nigel Rees",
"title" : "Sayings of the Century",
"price" : 8.95
}
]
来自
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
你知道更干净的正则表达式吗?什么是不必要的或应该添加到实际的正则表达式中?
【问题讨论】: