c# - Extract data from string using pattern -


hi have long string:

'bla bla bla... <img src="/uploads/photo.png" width="143" height="136" /> bla bla bla...' 

and want extract long string: image tag - width, height , of course path... maybe this:

<img src="*" width="*" height="*" /> 

but don't know how "*" data. can please suggest me code extract image path (*). might in c#, vb or java... anything. thanks!

don't use regex parse html. use html parser insted. e.g. can use htmlagilitypack:

var html = "bla... <img src=\"/uploads/photo.png\" width=\"143\" height=\"136\" /> bla..."; htmldocument doc = new htmldocument(); doc.loadhtml(html); var img = doc.documentnode.element("img"); var src = img.attributes["src"].value;       // "/uploads/photo.png" var width = img.attributes["width"].value;   // "143" var height = img.attributes["height"].value; // "136" 

or anglesharp

var parser = new htmlparser(); var doc = parser.parse(html); var img = doc.queryselectorall("img").firstordefault(); var src = img.attributes["src"].value;       // "/uploads/photo.png" var width = img.attributes["width"].value;   // "143" var height = img.attributes["height"].value; // "136" 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -