【问题标题】:Match alphanumerics, except only numbers匹配字母数字,仅数字除外
【发布时间】:2013-02-01 14:02:47
【问题描述】:

给出这个特定正则表达式背后想法的原始问题是Regex to find content not in quotes

让我们稍微修改一下原始示例:

INSERT INTO Notifify (to_email, msg, date_log, from_email, ip_from)
VALUES
    (
        :to_email,
        'test teste nonono',
        :22,
        :3mail,
        :ip_from
    )

我知道任何编程语言都不允许以数字开头的变量,但这并不意味着我们不能有需要匹配 :to_email:3mail:ip_from 而不是 @ 987654327@.

我们如何进行?我和我的朋友尝试过(理论上)这种方式->

  • 将所有字符串存储在一个集合中
  • 减去仅包含数字的集合

对于在线测试,我使用的是RegExr

【问题讨论】:

    标签: regex string-matching


    【解决方案1】:

    我不知道你使用哪种编程语言,但为什么不能检查行是否匹配:

    ^\s*:[0-9]+,?\s*$
    

    然后只用不匹配的线?

    【讨论】:

      【解决方案2】:

      前瞻将在这里工作

      \b(?=\d*[a-z])\w+\b
      

      如愿以偿

      \b\d*[a-z]\w*\b
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-19
        • 2020-01-15
        相关资源
        最近更新 更多