博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
您不需要正则表达式
阅读量:2523 次
发布时间:2019-05-11

本文共 1870 字,大约阅读时间需要 6 分钟。

by Rina Artstain

通过丽娜·阿斯特斯坦

您不需要正则表达式 (You Don’t Need a Regex for That)

I once had a web siteon which one could searchfor all sorts of things(as long as they’re strings)

我曾经有一个网站,可以搜索各种各样的东西(只要它们是字符串)

The items had titlesand content and moreso the search used a regexto help you explore

这些项目具有标题和内容,而且搜索使用正则表达式来帮助您探索

We had an ideawe gave it a trylet’s help you find morewe’ll add synonyms galore

我们有一个主意,我们给了它一个尝试的帮助,您可以找到更多我们将添加同义词galore

We tacked on those wordsto the end of the regexand straight to production(we didn’t have stress tests)

我们将这些字词加到正则表达式的末尾,然后直接投入生产(我们没有压力测试)

And lo and beholdthe site all but crashedso many timeoutswe all were abashed

瞧,这个站点几乎崩溃了,所以超时了,我们都震惊了

The change was revertedand there we sat hurtedtrying to thinkwhat brought us to this brink

更改被撤消,我们坐在那里痛苦地想着是什么使我们陷入了这种边缘

We researched those regexesand guess what we found:you should compile them firstif you want them around

我们研究了这些正则表达式并猜测我们发现了什么:如果需要它们,请先编译它们

So try that we didand it didn’t workthe site was still slowwe hoped it’s a quirk

所以尝试我们做到了,但没有成功,网站仍然很慢,我们希望这是一个怪癖

We tried many thingswe were all stressinguntil we decidedit’s time to start testing!

我们尝试了很多我们都在强调的事情,直到我们决定是时候开始测试了!

We drew up some schemesfor searching multiple wordsand what a surprisewe saw with our eyes

我们制定了一些搜索多个单词的方案,以及我们眼中看到的惊喜

String.Find()was 1000 times fasterthan all of those regexeswhich caused the disaster

String.Find()比引起灾难的所有正则表达式快1000倍

We learned our lessonI hope you did tooregexes are evilexcept for a few

我们吸取了教训我希望你也做过正则表达式是邪恶的,除了一些

If your regex is simplejust put it awayyou’re probably wastingyour time anyway

如果您的正则表达式简单易用,那么您可能正在浪费您的时间

All of us knowthe truth’s where it’s atin most of the casesYOU DON’T NEED A REGEX FOR THAT

我们所有人都知道,在大多数情况下,真相就在这里。您不需要正则表达式

P.S.Please excuse my bad rhymes and rhythm, I get paid to write software. Not poetry.

PS请原谅我不好的节奏和节奏,写软件我得到报酬。 不是诗歌。

翻译自:

转载地址:http://xdewd.baihongyu.com/

你可能感兴趣的文章
CentOS系统将UTC时间修改为CST时间
查看>>
redis常见面试题
查看>>
导航控制器的出栈
查看>>
玩转CSS3,嗨翻WEB前端,CSS3伪类元素详解/深入浅出[原创][5+3时代]
查看>>
iOS 9音频应用播放音频之播放控制暂停停止前进后退的设置
查看>>
Delphi消息小记
查看>>
HNOI2016
查看>>
JVM介绍
查看>>
将PHP数组输出为HTML表格
查看>>
Java中的线程Thread方法之---suspend()和resume() 分类: ...
查看>>
经典排序算法回顾:选择排序,快速排序
查看>>
BZOJ2213 [Poi2011]Difference 【乱搞】
查看>>
一道关于员工与部门查询的SQL笔试题
查看>>
Canvas基础
查看>>
[Hive - LanguageManual] Alter Table/Partition/Column
查看>>
可持久化数组
查看>>
去除IDEA报黄色/灰色的重复代码的下划波浪线
查看>>
Linux发送qq、网易邮件服务配置
查看>>
几道面试题
查看>>
【转】使用 WebGL 进行 3D 开发,第 1 部分: WebGL 简介
查看>>