REGEXP在JSON字符串中搜索

REGEXP在JSON字符串中搜索

本文介绍了MYSQL REGEXP在JSON字符串中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是regexp的初学者,我尝试搜索json格式的文本,但是我无法使其正常运行:

I'm a beginner in regexp and i try to search in json formatted text, but i cannot make it work right:

SELECT DISTINCT tag, body FROM pages
WHERE (body REGEXP BINARY '"listeListeOuiNon":".*1.*"')

它显示为带有

"listeListeOuiNon":"1"

"listeListeOuiNon":"1,2"

"listeListeOuiNon":"0,1" as expected

也是"listeListeOuiNon":"2" (not expected)

有什么主意吗?也许是因为它很贪婪,但我不确定...

Any idea?Maybe it's because it's greedy, but i'm not sure...

提前谢谢!

推荐答案

我会尝试将两个.*替换为[^"]* ...但这仅在您的listeListeOuiNon不能包含乱码" s,否则您还必须处理转义序列.基本上,使用.,您将匹配具有1在" "listListOuiNon":"之后的任何JSON字符串,即使它在另一个字段中也是如此,是的,因为它很贪心.

I would try to replace the two .* with [^"]*... That'll however only be sufficient if your listeListeOuiNon cannot contain litteral "s, or you'd have to also handle the escape sequence. Basically with the . you'll match any JSON string that has a 1 "after" "listListOuiNon":", even if it's in another field, and yes, that's because it's greedy.

这篇关于MYSQL REGEXP在JSON字符串中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:54