V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
JinTianYi456
V2EX  ›  正则表达式

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

  •  
  •   JinTianYi456 · 354 天前 · 527 次点击
    这是一个创建于 354 天前的主题,其中的信息可能已经有所发展或是发生改变。

    就参考这吧: 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 个来分别表示?

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

    4. 补充下问题,是指不清楚设计思路。匹配单词开始边界,和结尾边界,为啥需要设计为 2 种写法?
    yuezk
        2
    yuezk  
       353 天前
    4. 单词的开始边界和结束边界虽然都是边界,但是如果要区分这两个边界的话,肯定要用两个字符表示才能区分呀。你有更好的方法吗?
    JinTianYi456
        3
    JinTianYi456  
    OP
       353 天前
    @yuezk #2 其实我是想 在单词的开头不就是 开始边界吗? 你写成 结尾边界,肯定匹配不到。所以为何还区分 2 种?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   890 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 22:04 · PVG 06:04 · LAX 15:04 · JFK 18:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.