When is a issue too complex for a regular expression?

后端 未结 13 1010
执念已碎
执念已碎 2021-02-01 19:42

Please don\'t answer the obvious, but what are the limit signs that tell us a problem should not be solved using regular expressions?

For example: Why is a complete emai

13条回答
  •  礼貌的吻别
    2021-02-01 20:35

    Regular expressions are suited for tokenizing, finding or identifying individual bits of text, e.g. finding keywords, strings, comments, etc. in source code.

    Regular expressions are not suited for determining the relationship between multiple bits of text, e.g. finding a block of source code with properly paired braces. You need a parser for that. The parser can use regular expressions for tokenizing the input, while the parser itself determines how the different regex matches fit together.

    Essentially, you're going to far with your regular expressions if you start thinking about "balancing groups" (.NET's capture group subtraction feature) or "recursion" (Perl 5.10 and PCRE).

提交回复
热议问题