How can I combining the following RegExs into one expression?

蓝咒 提交于 2019-12-12 01:35:30

问题


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.


回答1:


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.




回答2:


stripcr(ReReplaceNoCase(arguments.string, "(<[^>]*>)", "", "ALL"))


来源:https://stackoverflow.com/questions/4540036/how-can-i-combining-the-following-regexs-into-one-expression

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!