开发者

C# reading html attribute value using regular expression

开发者 https://www.devze.com 2023-03-13 08:43 出处:网络
I have a string: str = \"<img src=\'http://server/path/a.jpg\' />blah blah blah blah\";开发者_如何学Go

I have a string:

str = "<img src='http://server/path/a.jpg' />blah blah blah blah";开发者_如何学Go

What would be the regular expression to find the attribute source value?

I do not want to use HTML Agility pack.

Regards,


Don't use regex to parse HTML. Use one of the many available parsers that suits your needs.

But if you really have to, for that sting this simple (and in many cases broken) regex could work for you:

\bsrc\s*=\s*["']([^"'>]+)


Use HTML agility pack; even for small things!

:: sigh ::

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号