› 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 · 7074 views
    This topic created in 3492 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   ·   Privacy   ·   Solana   ·   820 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:30 · PVG 05:30 · LAX 14:30 · JFK 17:30
    ♥ Do have faith in what you're doing.