正则表达式提取HTML图像性能 [英] RegEx for extracting HTML Image properties

查看:113
本文介绍了正则表达式提取HTML图像性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个图像标记中提取所有属性的正则表达式。

大家都知道,有许多畸形的HTML在那里,这样的格局已经覆盖到这些可能性。

我一直在寻找这种解决方案<一href="http://stackoverflow.com/questions/138313/how-to-extract-img-src-title-and-alt-from-html-using-php"相对=nofollow称号=如何提取IMG SRC标题和alt">http://stackoverflow.com/questions/138313/how-to-extract-img-src-title-and-alt-from-html-using-php但它并没有完全得到这一切:

我拿出这样的:

 (ALT |标题| SRC |高|宽)\ S * = \ s * [']?[\ W \ W] + [']
 

有没有我会想念任何可能性,或者更高效简单的模式?

编辑:
对不起,我会更加具体,我这样做是使用.NET所以它在服务器端。
我已经IMG标签的列表,现在我只需要解析的属性。

解决方案
  

大家都知道,有许多畸形的HTML在那里,这样的格局已经覆盖到这些可能性。

不会。如果你要解析的邪恶(来源不明)HTML使用HTML解析器。

I need a RegEx pattern for extracting all the properties of an image tag.

As we all know, there are lots of malformed HTML out there, so the pattern has to cover those possibilities.

I was looking at this solution http://stackoverflow.com/questions/138313/how-to-extract-img-src-title-and-alt-from-html-using-php but it didn't quite get it all:

I come up something like:

(alt|title|src|height|width)\s*=\s*["'][\W\w]+?["']

Is there any possibilities I'll be missing or a more efficient simple pattern?

EDIT:
Sorry, I will be more specific, I'm doing this using .NET so it's on the server side.
I've already a list of img tags, now I just need to parse the properties.

解决方案

As we all know, there are lots of malformed HTML out there, so the pattern has to cover those possibilities.

It won't. Use a HTML parser if you have to parse "evil" (from an unknown source) HTML.

这篇关于正则表达式提取HTML图像性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆