Performance and practice of lazy regex?

后端 未结 3 2059
轮回少年
轮回少年 2021-01-14 07:03

I read on the internet i should avoid lazy regex because of \'worse\' performance and \'bad\' practice. I never seen an example of either. I havent heard of an app

3条回答
  •  隐瞒了意图╮
    2021-01-14 07:52

    One thing you should try to ensure with any regular expression is that there's only one way for it to match a given match. That sounds weird, but there's an excellent article that demonstrates the point here... http://www.regular-expressions.info/catastrophic.html

    It's rare that you'll encounter this degree of catastrophic backtracking as illustrated in this article. But just in case, it's a good idea to run a simple benchmark whenever writing a regular expression that'll see heavy use.

提交回复
热议问题