如何将以下正则表达式组合成一个表达式?

发布于 2024-10-09 00:21:40 字数 436 浏览 0 评论 0原文

我正在使用以下正则表达式从字符串中去除 HTML 标签

<[^>]*>

,但这并不能消除空行。我发现另一个正则表达式成功删除了任何空行:

[#Chr(13)##Chr(10)#]+

我尝试将两者结合起来:

ReReplaceNoCase(arguments.string, "(<[^>]*>)([#Chr(13)##Chr(10)#]+)", "", "ALL")

但这不起作用。我正在使用 ColdFusion 来执行此操作,这应该可以解释 # 符号。

我认为 () 用于对正则表达式中的运算符进行分组,但在我尝试组合两个表达式时它似乎不起作用。

I'm using the following RegEx to strip HTML tags from a string

<[^>]*>

This does not get rid of blank lines, however. I found this other RegEx that successfully removes any blank lines:

[#Chr(13)##Chr(10)#]+

I tried to combine both as such:

ReReplaceNoCase(arguments.string, "(<[^>]*>)([#Chr(13)##Chr(10)#]+)", "", "ALL")

But this does not work. I'm using ColdFusion to do this, which should explain the # signs.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时常饿 2024-10-16 00:21:40

假设您拥有的两个正则表达式可以按您想要的方式工作,那么您可以使用交替组合它们:

<[^>]*>|[#Chr(13)##Chr(10)#]+

我强烈怀疑您发布的正则表达式实际上正常工作。我建议您不要使用正则表达式来解析 HTML,因为 HTML 不是常规语言。请改用 HTML 解析器。

Assuming that the two regular expressions you have work as you want then you can combine them using an alternation:

<[^>]*>|[#Chr(13)##Chr(10)#]+

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.

盗梦空间 2024-10-16 00:21:40
stripcr(ReReplaceNoCase(arguments.string, "(<[^>]*>)", "", "ALL"))
stripcr(ReReplaceNoCase(arguments.string, "(<[^>]*>)", "", "ALL"))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文