代码之家  ›  专栏  ›  技术社区  ›  Yuseferi

在Select mysql中使用正则表达式

  •  1
  • Yuseferi  · 技术社区  · 9 年前

    我正在寻找一种在Mysql的SELECT短语中使用正则表达式的解决方案,例如,我有以下记录

    title = "title"
    description = "this is testing title with id number 342 nice"
    

    现在我想选择标题和 从该记录中(注意,所有描述 number 模式)所以我正在寻找一种解决方案来选择描述字段中的标题和数字。

    1 回复  |  直到 9 年前
        1
  •  1
  •   KMS    9 年前

    试试这个

    SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(<fieldname>,']',1),'[',-1) AS extracted
    FROM <tablename>;
    

    更新:

    SELECT title, SUBSTRING_INDEX(SUBSTRING_INDEX(description,']',1),'[',-1) AS extracted
    FROM <tablename>;//Replace with your table name here