为什么正则表达式如此有争议? [英] Why are regular expressions so controversial?

查看:33
本文介绍了为什么正则表达式如此有争议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在探索正则表达式(也称为 RegEx-es)时,很多人似乎将正则表达式视为圣杯.看起来如此复杂的东西 - 必须是任何问题的答案.他们倾向于认为每个问题都可以使用正则表达式解决.

When exploring regular expressions (otherwise known as RegEx-es), there are many individuals who seem to see regular expressions as the Holy Grail. Something that looks so complicated - just must be the answer to any question. They tend to think that every problem is solvable using regular expressions.

另一方面,也有很多人不惜一切代价试图避免使用正则表达式.他们试图找到一种绕过正则表达式的方法,并为此接受额外的编码,即使正则表达式会是一个更紧凑的解决方案.

On the other hand, there are also many people who try to avoid regular expressions at all cost. They try to find a way around regular expressions and accept additional coding just for the sake of it, even if a regular expressions would be a more compact solution.

为什么正则表达式被认为如此有争议?是否对它们的工作方式存在广泛的误解?或者人们普遍认为正则表达式通常很慢?

Why are regular expressions considered so controversial? Is there widespread misunderstandings about how they work? Or could it be a broad belief that regular expressions are generally slow?

推荐答案

我不认为人们反对正则表达式是因为它们很慢,而是因为它们难以阅读和编写,而且很难理解做对.虽然在某些情况下,正则表达式为问题提供了有效、紧凑的解决方案,但它们有时会被硬塞到最好使用易于阅读、可维护的代码段代替的情况.

I don't think people object to regular expressions because they're slow, but rather because they're hard to read and write, as well as tricky to get right. While there are some situations where regular expressions provide an effective, compact solution to the problem, they are sometimes shoehorned into situations where it's better to use an easy-to-read, maintainable section of code instead.

这篇关于为什么正则表达式如此有争议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆