如何将以下RegExs组合为一个表达式? [英] How can I combining the following RegExs into one expression?
问题描述
我正在使用以下RegEx从字符串中剥离HTML标记
I'm using the following RegEx to strip HTML tags from a string
<[^>]*>
但是,这并不能消除空白行。我找到了另一个RegEx,可以成功删除任何空白行:
This does not get rid of blank lines, however. I found this other RegEx that successfully removes any blank lines:
[#Chr(13)##Chr(10)#]+
我试图将两者合并:
ReReplaceNoCase(arguments.string, "(<[^>]*>)([#Chr(13)##Chr(10)#]+)", "", "ALL")
但这不起作用。我正在使用ColdFusion进行操作,这应该解释#
的迹象。
But this does not work. I'm using ColdFusion to do this, which should explain the #
signs.
我认为()
用于在RegEx中对运算符进行分组,但在我尝试将两个表达式组合在一起时似乎不起作用。
I thought the ()
were used to group operators in RegEx, but it does not seem to work in my attempt to combine the two expressions.
推荐答案
假设您有两个正则表达式都可以使用,则可以使用交替方式将它们组合在一起:
Assuming that the two regular expressions you have work as you want then you can combine them using an alternation:
<[^>]*>|[#Chr(13)##Chr(10)#]+
我强烈怀疑您发布的正则表达式不实际上可以正常工作。我建议您不要使用正则表达式来解析HTML,因为HTML不是常规语言。请改用HTML解析器。
I strongly suspect though that the regular expressions you have posted don't in fact work correctly. I'd advise you not to use regular expressions to parse HTML as HTML is not a regular language. Use an HTML parser instead.
这篇关于如何将以下RegExs组合为一个表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!