在MySQL中需要REGEXP匹配 [英] Need REGEXP Matching in MySQL

查看:69
本文介绍了在MySQL中需要REGEXP匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想匹配一个看起来像这样的字符串:

I want to match a String which looks like this:

[lang_de]Hallo![/lang_de][lang_en]Hello![/lang_en]HeyHo[lang_es]Hola![/lang_es]

如果存在未被lang_tags包围的文本(在本示例中为HeyHo),我希望匹配返回true.也可以将其放置在字符串的开头或结尾.

I want the matching to return true if there is text which is not enclosed by lang_tags (in this example: HeyHo). It could also be positioned at the beginning or end of the string.

空格不应匹配,例如[lang_de]Tisch[/lang_de] [lang_en]Table[/lang_en]不应引起匹配.

Whitespace should NOT match, e.g. [lang_de]Tisch[/lang_de] [lang_en]Table[/lang_en] should not cause a match.

我无法使用前瞻性或回溯性,因为MySQL似乎不支持此功能.

I can't use lookahead or lookback, because MySQL doesnt seem to support this.

有什么建议吗?

推荐答案

尝试此正则表达式:

'^ *[^[ ]|\\[/lang_[a-z]{2}\\] *[^[ ]'

这是您可以使用的方式:

This is how you can use it:

select * 
from <table> 
where <field> regexp '^ *[^[ ]|\\[/lang_[a-z]{2}\\] *[^[ ]'

它应该处理所有情况:

  • 之前
  • 之后
  • 不是空格

这篇关于在MySQL中需要REGEXP匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆