A
A
AZshar2018-07-31 12:09:49
Regular Expressions
AZshar, 2018-07-31 12:09:49

How to set a regular expression to find src only for img?

Beaver everyone.
I have been suffering for 3 days already, there is CKEditor, in which I load images via base64image, everything suits me, but I need to store the path to 1 image in the database. (i.e. there can be 20 of them, but we take 1 img and save its src to the database).
'/src="([^"]+)/' I did this, everything suits, but this is finding src for all tags, not just for img
Help comrades, thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2018-07-31
@AZshar

symfony.com/doc/current/components/dom_crawler.html

$dom = new Crawler($html);
$images = $dom->filterXPath('//img')->extract(array('src')); // extract images

A
arhan89, 2018-07-31
@arhan89

let regex = /<img.*?src="(.*?)"/;
let src = regex.exec( htmlString )[1];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question