Reference to groups in a MySQL regex?

前端 未结 2 1325
死守一世寂寞
死守一世寂寞 2020-12-01 20:51

How to reference to a group using a regex in MySQL? I tried:

REGEXP \'^(.)\\1$\'

but it does not work. How to do this?

相关标签:
2条回答
  • 2020-12-01 21:31

    You can't, there is no way to reference regex capturing groups in MySql.

    0 讨论(0)
  • 2020-12-01 21:43

    (Old question, but top search result)

    For MySQL 8:

    SELECT REGEXP_REPLACE('stackoverflow','(.{5})(.*)','$2$1');
    -- "overflowstack"
    

    You can create capture groups with (), and you can refer to them using $1, $2, etc.

    0 讨论(0)
提交回复
热议问题