How important is knowing Regexs?

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

    It is not clear what kind of answer you are expecting.

    I can imagine roughly three kinds of answer to this question:

    1. Regexen are essential to the education of professional programmers. They enable the use the powerful unix shell tools, and regex-based search-replace can dramatically cut down on text-munging handiwork that is a part of a programmer's life. Programmers that do not know regexen are just intelectually lazy which is a very bad trait for a programmer.

    2. Regexps are kinda useful depending on the application domain. Surely, knowing how to write regexps is a valuable tool a programmer's chest, but most of the time you can do fine without using them. Also, regexps tend to be very hard to read, so abuse must be strongly discouraged.

    3. Some nutcases like to put regexs everything (I'm looking at you, the perl guy who implemented a regex-based tetris in perl). But really, they are just a bit of computer science trivia whose only practical use is in writing parsers. They are widely taught because they make a good teaching topic on which to evaluate students, and like most such topics it can forgotten the second you step out of the exam room.

    You will notice the careful use of the plural forms "regexen" (pro), "regexps" (careful neutral) and "regexs" (con).

    Personally, I am of the first kind. Good programmers like to learn new languages, and they hate repetitive handiwork.

提交回复
热议问题