sql - Pulling a substring starting and ending with a special character from rows of a MySQL table -


i have table articles column body.

inside body column, have lot of rows having <img> tags, e.g

----------------------------------------            body ---------------------------------------- <img src="www.abc.com/1"> artcle 1 article 2 <img src="www.abc.com/2"> article 3 article 4 

now want src portions, www.abc.com/1,www.abc.com/2,etc.

i got such rows using

select body articles body `%img%` 

how can extract link (src) portion?

you can use substr method locate , locate reverse find beginning double quote , ending double quote src="www.abc.com/1" so:

select      body,     substr(         body,          locate('"',body)+1,          (char_length(body) - locate('"',reverse(body)) - locate('"',body))     ) 'src url' articles  body '%img%' 

demo


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -