正则表达式值得麻烦吗? [英] Are regular expressions worth the hassle?

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

问题描述

令我惊讶的是,大多数开发人员对正则表达式的理解并不深刻.对于很多使用正则表达式的问题,我也可以使用大量的代码 代替.当然,它可能会比较慢,并且对于诸如电子邮件验证之类的代码来说可能要20行,但是如果代码的性能不是非常重要,那么是否合理地假设不使用正则表达式是否合理呢?

It strikes me that regular expressions are not understood well by the majority of developers. It also strikes me that for a lot of problems where regular expressions are used, a lump of code could be used instead. Granted, it might be slower and be 20 lines for something like email validation, but if performance of the code is not desperately important, is it reasonable to assume that not using regular expressions might be better practise?

我在考虑代码的维护,而不是直线执行时间.

I'm thinking in terms of maintenance of the code rather that straight line execution time.

推荐答案

每当我使用Regex时,我总是尝试发表评论以确切解释其结构,因为我同意您的观点,即并非所有开发人员都理解它们并返回到regex,即使您自己编写,也可能很难再次理解.

Whenever i use a Regex i always try to leave a comment explaining exactly how it's structured because I agree with you that not all developers understand them and going back to a regex, even if you've written it yourself, can be a headache to understand again.

也就是说,它们肯定有用途.尝试从没有文本框的文本框中删除所有html元素!

That said, they definitely have their uses. Try stripping out all html elements from a box of text without it!

这篇关于正则表达式值得麻烦吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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