【发布时间】:2015-02-28 06:56:41
【问题描述】:
我必须使用正则表达式从 html 文本中找到特定模式
例如:
我的字符串是
<table border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td><p align="justify"><u>Counsel appeared</u></p><p align="justify"><a name="COUNSEL" id="COUNSEL"></a>K. P. Garg CA<b>for the Appellant</b>.: A. K. Monga, Sr. DR <b>for theRespondent</b></p><p align="justify"><b><u><a name="JUDGE" id="JUDGE"></a>R. P.TOLANI, JM.</u></b></p><p align="justify">testing</p>..........and so on
我想从 html 文本中删除 <p align="justify"><u>Counsel appeared</u></p><p align="justify"><a name="COUNSEL" id="COUNSEL"></a>K. P. Garg CA<b>for the Appellant</b>.: A. K. Monga, Sr. DR <b>for theRespondent</b></p> 这部分。 html标签中包含的文本是动态的。
为此我写了以下正则表达式
gsub(/<p align="justify"><u>counsel appeared<\/u><\/p><p align="justify"><a name="counsel" id="counsel"><\/a>.*<b>.*<\/b><\/p>/i, '')
但它从“律师”中删除了整个文本出现
直到结束。那么我如何从上面的 html 字符串中删除特定部分? 谁能帮我修改我的正则表达式?
【问题讨论】:
-
我并不是想成为 那个人,但也许你应该使用 html 解析器而不是依赖正则表达式。看看这个著名的 SO 答案:stackoverflow.com/questions/1732348/…
标签: regex ruby-on-rails-4