【问题标题】:Regex to match exact word without spaces正则表达式匹配不带空格的确切单词
【发布时间】:2015-12-15 03:53:04
【问题描述】:

我有如下查询:

SELECT * from table_name where lastname regexp "[[:<:]]Smith[[:>:]]"

这会返回

  • De Smith
  • Smith

我只需要检索Smith

我什至尝试了以下

SELECT * from surnames where last_name regexp "[[:<:]][^\s]Smith[[:>:]]"

【问题讨论】:

    标签: mysql regex regex-negation


    【解决方案1】:

    我可能弄错了你的要求,但如果你想完全匹配姓氏,那么你可以使用等号运算符:

    SELECT * from table_name where TRIM(lastname) = 'Smith'
    

    我在lastname 字段中使用了TRIM(),以防可能出现前导或尾随空格。

    【讨论】:

    • 感谢您的回答。这实际上返回一个空值
    • 您能否通过向我们展示真实数据的样子来更新您的问题?
    猜你喜欢
    • 2018-06-12
    • 1970-01-01
    • 2017-12-23
    • 2013-07-09
    • 1970-01-01
    • 2016-12-01
    • 2017-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多