简体   繁体   English

正则表达式:HTML中的可选HTML标签?

[英]Regex: Optional HTML tags in HTML?

我需要从HTML解析一些值。

You can't parse (X)HTML with RegEx , so don't do it. 您无法使用RegEx解析(X)HTML ,所以不要这样做。 You need to use a proper parser that will build you a Document Object Model (DOM). 您需要使用适当的解析器来构建文档对象模型(DOM)。 As you have tagged your question with JavaScript, I recommend that you use jQuery to build an object graph of your HTML, simply like this: 用JavaScript标记问题后,建议您使用jQuery构建HTML的对象图,就像这样:

var $document = $(html);

This $document object can now be operated on with methods like $document.find() to dig out the elements you want from the HTML. 现在,可以使用诸如$document.find()类的方法来操作该$document对象,以从HTML中找出所需的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM