When is a issue too complex for a regular expression?

后端 未结 13 1133
执念已碎
执念已碎 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:27

    Sure sign to stop using regexps is this: if you have many grouping braces '()' and many alternatives '|' then it is a sure sign that you try to do a (complex) parsing with regular expressions.

    Add to the mix Perl extensions, backreferences, etc and soon you have yourself a parser that is hard to read, hard to modify, and hard to reason about it's properties (e.g. is there an input on which this parser will work in a exponential time).

    This is a time to stop regexing and start parsing (with hand-made parser, parser generators or parser combinators).

提交回复
热议问题