【问题标题】:how can I delete this regex with mysql我怎样才能用mysql删除这个正则表达式
【发布时间】:2022-01-19 13:49:09
【问题描述】:

我有一个 UDF regex_replace 替换 CASEINSENSITIVE 一个正则表达式。现在我想在这个字符串中得到()里面的字符串。我做到了:

    SELECT regex_replace('[^0-9{MC.D}]+','',"HPLC Labor Öttl 1 Raumtemperatur(MC1.D.03.031)");

输出是不需要的:C1mmMC1.D.03.031

我需要。仅限MC1.D.03.031。 如何使用适合我的 UDF 的正则表达式来做到这一点?

谢谢

【问题讨论】:

    标签: mysql regexp-replace


    【解决方案1】:

    你可以使用SUBSTRING_INDEXhttps://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_substring-index:

     SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('HPLC Labor Öttl 1 Raumtemperatur(MC1.D.03.031)', '(', -1), ')', 1) ;
    
    mysql> SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('HPLC Labor Öttl 1 Raumtemperatur(MC1.D.03.031)', '(', -1), ')', 1) ;
    +------------------------------------------------------------------------------------------------------+
    | SUBSTRING_INDEX(SUBSTRING_INDEX('HPLC Labor Öttl 1 Raumtemperatur(MC1.D.03.031)', '(', -1), ')', 1)  |
    +------------------------------------------------------------------------------------------------------+
    | MC1.D.03.031                                                                                         |
    +------------------------------------------------------------------------------------------------------+
    1 row in set (0.00 sec)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 2016-11-09
      相关资源
      最近更新 更多