使用HTML邮件中的正则表达式在标签之间获取文本

时间:2018-03-21 07:07:21

标签: javascript regex

我遇到了一种HTML邮件格式,"<![if !supportLists]>" and "<![endif]>"标记之间存在一些文字。我想使用正则表达式提取这些标记之间的文本。这是一个示例文本格式 输入:
    "<![if !supportLists]><span style='mso-list:Ignore'>Index<span style='font:7.0pt "Times New Roman"'> Value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><![endif]>"

预期输出:"Index Value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"

1 个答案:

答案 0 :(得分:0)

不要像@Justinas那样使用正则表达式,在你的情况下,你可以尝试使用像jQuery这样的api:

str = '<![if !supportLists]><span style="mso-list:Ignore">Index<span style="font:7.0pt Times New Roman"> Value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><![endif]>'

$(str).text();