I have a table named posts.
It contains id and post_content:
ID post_title post_content
1 aaaa <p>AAaa</p><img src="https://domain/uploads/aa.jpg"><p>Addd<img src="https://domain/uploads/assssa.jpg"></p>
2 bbb <img src="https://domain/uploads/bbbb.jpg"><p>xxxxx<img src="https://domain/uploads/xxxxx.jpg"></p>
3 ccc <p>aaaaa</p><img src="https://domain/uploads/aa.jpg">
I want to extract the image src from each post_content with specific domain. Each post_content has multiple images.
Like I only want to get images with url like this:
<img src="https://aaaaa.co.jp/uploads/">
Note: <img src="">
can have width, height, class or id inside.
Like this:
<img src="" class="" id="">
OR
<img width="" height="" src="" class="" id="">
.
I already tried this one from here: Extract the URL from img src with a mysql query
Some of it returns the image url but some of it wont.
This is my query so far:
SELECT
post.ID,
post.post_title,
SUBSTR(SUBSTR(post.post_content,
LOCATE('src="', post.post_content) + 5),
1,
LOCATE('"',
SUBSTR(post.post_content,
LOCATE('src="', post.post_content) + 5)) - 1) AS 'src'
FROM
tokyo_posts post;
So this is my desired output:
ID post_title post_content
1 aaaa https://domain/uploads/aa.jpg
1 aaaa https://domain/uploads/assssa.jpg
2 bbb https://domain/uploads/bbbb.jpg
2 bbb https://domain/uploads/xxxxx.jpg
3 ccc https://domain/uploads/aa.jpg
Note: I'm using a wordpress database. I'm gonna use this query for import image purposes.
Mysql version: 5.6.42