有对 posix-正则 有研究的吗?问下

2023-05-09 22:09:08 +08:00
 JinTianYi456

就参考这吧: https://dev.mysql.com/doc/refman/5.7/en/regexp.html

[.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 个来分别表示?

555 次点击
所在节点    正则表达式
3 条回复
JinTianYi456
364 天前
感谢另一网友的提点。当时可能太累了,一下没想通
1. [ 是关键字,比如 [ab] 表示 a/b , 这里的 [.~.] 本意是用来表示 ~ 这个字符,所以语法是 [[.~.]] (可以理解为 [~])
2. 好像是用来匹配 大小写或其它变体写法,比如 a/A/那种看起来像 a 的字符我也不知道叫啥
3. 同 1

4. 补充下问题,是指不清楚设计思路。匹配单词开始边界,和结尾边界,为啥需要设计为 2 种写法?
yuezk
364 天前
4. 单词的开始边界和结束边界虽然都是边界,但是如果要区分这两个边界的话,肯定要用两个字符表示才能区分呀。你有更好的方法吗?
JinTianYi456
364 天前
@yuezk #2 其实我是想 在单词的开头不就是 开始边界吗? 你写成 结尾边界,肯定匹配不到。所以为何还区分 2 种?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/938721

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX