V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
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 · Mar 4, 2017 · 6760 views
    This topic created in 3354 days ago, the information mentioned may be changed or developed.

    我在使用 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 replies    2017-03-05 20:14:52 +08:00
    ltux
        1
    ltux  
       Mar 5, 2017
    1, mysql 的正则表达式不支持 non-capturing group (?:XYZ) 这种语法
    2, 即使去掉 ?:,你的正则表达式依旧不对。给你个参考:
    ^(www\.)?([a-z0-9]+(-[a-z0-9]+)*\.)[a-z]{2,}$
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5705 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 06:55 · PVG 14:55 · LAX 23:55 · JFK 02:55
    ♥ Do have faith in what you're doing.