[.characters.]
Within a bracket expression (written using [ and ]), matches the sequence of characters of that collating element.
mysql> SELECT '~' REGEXP '[[.~.]]'; -> 1
为啥不是单[?结果也是 1 呀
mysql> SELECT '~' REGEXP '[.~.]';
[=character_class=]
Within a bracket expression (written using [ and ]), [=character_class=] represents an equivalence class.
里面没举例,可否写个例子?
[:character_class:]
Within a bracket expression (written using [ and ]), [:character_class:] represents a character class that matches all characters belonging to that class.
mysql> SELECT 'justalnums' REGEXP '[[:alnum:]]+'; -> 1
为啥不是单[?结果也是 1 呀
mysql> SELECT 'justalnums' REGEXP '[:alnum:]+';
[[:<:]], [[:>:]]
These markers stand for word boundaries. They match the beginning and end of words, respectively.
怎么需要 2 个来分别表示?
1
JinTianYi456 OP 感谢另一网友的提点。当时可能太累了,一下没想通
1. [ 是关键字,比如 [ab] 表示 a/b , 这里的 [.~.] 本意是用来表示 ~ 这个字符,所以语法是 [[.~.]] (可以理解为 [~]) 2. 好像是用来匹配 大小写或其它变体写法,比如 a/A/那种看起来像 a 的字符我也不知道叫啥 3. 同 1 4. 补充下问题,是指不清楚设计思路。匹配单词开始边界,和结尾边界,为啥需要设计为 2 种写法? |
2
yuezk 2023-05-10 14:42:29 +08:00
4. 单词的开始边界和结束边界虽然都是边界,但是如果要区分这两个边界的话,肯定要用两个字符表示才能区分呀。你有更好的方法吗?
|
3
JinTianYi456 OP @yuezk #2 其实我是想 在单词的开头不就是 开始边界吗? 你写成 结尾边界,肯定匹配不到。所以为何还区分 2 种?
|