How important is knowing Regexs?

前端 未结 16 1623
没有蜡笔的小新
没有蜡笔的小新 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:11

    I think knowing a regex is a quite important skill. While the usage of regex in a programming environment/language is question of maintainable code, I find the knowledge of regex to be useful with some commands (say egrep), editors (vim, emacs etc.). Using a regex to do a find and replace in vim is very handy when you have a text file and you want to do some formatting once in a while.

    0 讨论(0)
  • 2021-02-06 06:12

    When you have to parse something (ranging from simple date strings to programming languages) you should know your tools and regular expressions are one of them.

    But you should also know what you can do with regexes and what not. At this point it comes in handy if you know the Chomsky hierarchy hierarchy. Otherwise you end up trying to use regular expressions to parse context-sensitive languages and wonder why you can't get your regex right.

    0 讨论(0)
  • 2021-02-06 06:13

    In the Steve Yegge's article, Five Essential Phone Screen Questions, you should read the section "Area Number Three: Scripting and Regular Expressions".

    Steve Yegge has some interesting points. He gives real world problems he has encountered with clients having to parse 50,000 files for a particular pattern of a phone number. The applicants who know regular expressions tear through the problem in a few minutes while those who don't write monster multi-hundred line programs that are very unwieldy. This article convinced me I should learn regular expressions.

    0 讨论(0)
  • 2021-02-06 06:15

    REs let you solve relatively complex problems that would otherwise require you to code up full parsers with backtracking and all that messy sort of stuff. I liken the use of REs to using chainsaws to chop down a tree instead of trying to do it with a piece of celery.

    Once you've learned how to use the chainsaw safely, you'll never go back. People who continue to spout anti-RE propaganda will never be as productive as those of us who have learned to love them.

    So yes, you should know how to use REs, even if you understand only the basic constructs. They're a tool just like any other.

    0 讨论(0)
  • 2021-02-06 06:16

    The fact that all languages support regexs should mean something !

    0 讨论(0)
  • 2021-02-06 06:19

    A developer thought he had one problem and tried to solve it using regex. Now he has 2 problems.

    0 讨论(0)
提交回复
热议问题