How important is knowing Regexs?

前端 未结 16 1627
没有蜡笔的小新
没有蜡笔的小新 2021-02-06 05:23

My personal experience is that regexs solve problems that can\'t be efficiently solved any other way, and are so frequently required in a world where strings are as important as

16条回答
  •  余生分开走
    2021-02-06 06:21

    Not a brilliant answer but everywhere I've worked the following holds true

    0 < Number of people who (fully) understand regex < 1

    If I knew how to do it I'd write that previous expression as a regex, but I can't. The best I could come up with on the fly is s/fully/a little/g - that's my limit (and that's probably not a regex).

    A more serious answer is that the right regex will solve all kinds of problems, with one(ish) line of code. But you'll have real problems debugging it if it goes wrong. Therefore IMHO a complex regex however 'clean/clever' is a liability, if it takes ten lines of code to replicate it, why's that a problem, is memory/disk space suddenly expensive again?

    BTW I'd love to know if regexs are fast compared to code equivalent.

提交回复
热议问题