Search for text between delimiters in MySQL

前端 未结 11 2662
情歌与酒
情歌与酒 2021-02-08 03:39

I am trying to extract a certain part of a column that is between delimiters.

e.g. find foo in the following

test \'esf :foo: bar

So in the above I\'d wa

11条回答
  •  眼角桃花
    2021-02-08 03:50

    mid(col, 
        locate('?m=',col) + char_length('?m='), 
        locate('&o=',col) - locate('?m=',col) - char_length('?m=') 
    )
    

    A bit compact form by replacing char_length(.) with the number 3

    mid(col, locate('?m=',col) + 3, locate('&o=',col) - locate('?m=',col) - 3)
    

    the patterns I have used are '?m=' and '&o'.

提交回复
热议问题