Why can't Regular Expressions use keywords instead of characters?

后端 未结 14 3220
甜味超标
甜味超标 2021-02-20 06:46

Okay, I barely understand RegEx basics, but why couldn\'t they design it to use keywords (like SQL) instead of some cryptic wildcard characters and symbols?

Is it for pe

相关标签:
14条回答
  • 2021-02-20 07:32

    If the language you are using supports Posix regexes, you can use them.

    An example:

    \d
    

    would be the same as

    [:digit:]
    

    The bracket notation is much clearer on what it is matching. I would still learn the "cryptic wildcard characters and symbols, since you will still see them in other people's code and need to understand them.

    There are more examples in the table on regular-expressions.info's page.

    0 讨论(0)
  • 2021-02-20 07:34

    This is much earlier than PERL. The Wikipedia entry on Regular Expressions attributes the first implementations of regular expressions to Ken Thompson of UNIX fame, who implemented them in the QED and then the ed editor. I guess that the commands had short names for performance reasons, but much before being client-side. Mastering Regular Expressions is a great book about regular expressions, which offers the option to annotate a regular expression (with the /x flag) to make it easier to read and understand.

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