【发布时间】:2014-04-07 10:09:04
【问题描述】:
如何使用正则表达式将 HTML 表格标签与字符串分开?
var sTabString =' ... <table > <table ... any string ... id="Unique_1" ... any string ...> abc def <table > ... ';
var sReg = '< *table .* id *= *"Unique_1" .*>';
var sRegEx = new RegExp(sReg);
var sResult = sTabString .match(sRegEx);
alert(sResult);
我希望打开标签的所有属性如下:
<table ... any string ... id="Unique_1" ... any string ...>
【问题讨论】:
-
What is the XY problem?。 为什么你需要这样做?
-
我同意@h2ooooooo - 我也想链接XY问题。告诉我们您要实现什么目标,因为我们 98% 确定您的任务不需要正则表达式。
-
@ElmoVanKielmo 我把它改成了那个,因为它很混乱。据我所知,给定字符串
<table id="foo" class="table-bordered"><thead><tr><th>Hi</th></tr></thead></table>,他想要<table id="foo" class="table-bordered">(打开标签)。 -
你能发布完整的表格代码并告诉我们你想提取什么吗?
-
我正在尝试从文本中读取某些 HTML 表格。
标签: javascript regex