V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
anonymoustian
V2EX  ›  MySQL

Mysql 中正则匹配错误 [Err] 1139

  •  
  •   anonymoustian · 2017-03-04 23:59:44 +08:00 · 6201 次点击
    这是一个创建于 2601 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我在使用 MYSQL 中的正则匹配域名时,出现了错误:

    [Err] 1139 - Got error 'repetition-operator operand invalid' from regexp

    正则表达式是:

    WHERE lt_sh_a_graph.rvalue REGEXP "^(www.)?(?:a-zA-Z0-9.)[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$"

    该正则用于匹配 二级域名或者带 www 的三级域名

    例如

    baidu.com

    www.baidu.com

    而其他的则过滤掉

    请问这个错误应该怎么处理?

    1 条回复    2017-03-05 20:14:52 +08:00
    ltux
        1
    ltux  
       2017-03-05 20:14:52 +08:00
    1, mysql 的正则表达式不支持 non-capturing group (?:XYZ) 这种语法
    2, 即使去掉 ?:,你的正则表达式依旧不对。给你个参考:
    ^(www\.)?([a-z0-9]+(-[a-z0-9]+)*\.)[a-z]{2,}$
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3221 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:34 · PVG 21:34 · LAX 06:34 · JFK 09:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.