正则表达式匹配两个“标识点”之间的内容
程序员文章站
2024-03-24 18:24:40
...
正则匹配两个字符串直接的内容
示例说明
如何用正则取出所有的id值
{
"state": 0,
"data": [{
"{
"state": 0,
"data": [{
"id": "228937",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552976802,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552976882"
}, {
"id": "228920",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552976423,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552976521"
}, {
"id": "228919",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552976393,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552976521"
}, {
"id": "228915",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552976066,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552976101"
}, {
"id": "228914",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552976066,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552976101"
}, {
"id": "228593",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552890552,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552890661"
}, {
"id": "228592",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552890444,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552890481"
}, {
"id": "228591",
"msg": "{\"fromAccountNick\228937",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552976802,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552976882"
}, {
"id": "228920",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552976423,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552976521"
}, {
"id": "228919",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552976393,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552976521"
}, {
"id": "228915",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552976066,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552976101"
}, {
"id": "228914",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552976066,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552976101"
}, {
"id": "228593",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552890552,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552890661"
}, {
"id": "228592",
"msg": "{\"fromAccountNick\":\"游客CBD57****D8E75\",\"elems\":[{\"type\":\"TIMTextElem\",\"content\":{\"text\":\"love_msg\"}}],\"time\":1552890444,\"fromaccount\":\"游客CBD57****D8E75\"}",
"fromaccount": "游客CBD57****D8E75",
"dottime": "0:00",
"parent_id": "",
"time": "1552890481"
}, {
"id": "228591",
"msg": "{\"fromAccountNick\
取出所有id值
其实就是取出 “id”:" 与 ","msg之间的内容
正则:(?<=("id":")).*?(?=","msg)
取出所有id值包括前面的标识
正则:(?=("id":")).*?(?=","msg)
取出所有id值包括前面的标识和后面的标识
正则:(?=("id":")).*?(?<=","msg)
知识点
-
(?<=标识A) 匹配一个位置,而不是字符.这个位置在 标识A 后面
-
(?=标识B) 匹配一个位置,而不是字符.这个位置在 标识B 前面
-
.* 这两个位置之间的所有字符.贪婪匹配模式
-
.*? 这两个位置之间的所有字符.懒惰匹配模式,也叫非贪婪模式
上一篇: 2018前端面试题(八)
下一篇: 数据表自增主键(int)溢出解决方案整理