使用普通防爆pressions的缺点缺点、普通、pressions

2023-09-05 01:33:09 作者:继续难过的怕人。

最近我被告知我的经理不依赖于很多正则表达式,因为它有很多的缺点。当我想了解更多,我听说它有一个像正则表达式的问题可能会导致内存泄漏的一些对象将继续即使在使用后挂弦参考?

Recently I was advised by my manager not to depend much on Regex as it has lot of disadvantages. When I tried to learn more , I hear that it has issues like regex can result in memory leak as some objects continue to hang on strings references even after use ?

.NET正则表达式"内存泄漏"调查

因此​​,正确地说,REG-EX导致内存开销,不应使用,如果您有其他的选择吗?是否有任何其他不利为reg-EX(除了它是很难学习:))

So it it right to say that reg-ex causes memory overheads and should not be used if you have other options ? Is there any other disadvantaged to reg-ex (apart from it being tough to learn :) )

PS我开发一个应用程序(C#.NET)类似的网络爬虫中提取所有的HREF和类似标题的一些其他信息,etc..I在使用,而不是REG-EX的HTML敏捷包的选项meta标签。

P.S I am developing an application (c#.net) similar to web crawler which extracts all hrefs and some other information like title, meta tags etc..I have the option of using HTML Agility pack instead of reg-ex.

推荐答案

使得code难以阅读。在大多数情况下,即使有更详细的code的费用,你最好不使用常规的前pressions。那件昂贵的性能影响和退化的code可读性意味着你不使用,在大多数的情况下,特别是,越简单的人与复杂的正则表达式。

Makes the code difficult to read. Most of the time, even at the expense of having more verbose code, you are better off not using regular expressions. The costly performance impact and the degradation in the readability of the code means that you don't use regexes in most of the cases, especially, the simpler ones and the complex ones.

和的目的,你都在提(解析HTML等),经常EX pressions简单的不能完成这项工作(因为HTML是不是一个正规的语言)。它就像有一把锤子,一切看起来都像钉子。

And for the purpose you are mentioning ( parsing HTML etc. ), regular expressions simple cannot get the job done ( because HTML is not a regular language ). It is is like having a hammer and everything looks like a nail.

 
精彩推荐