Why does checking this string with Regex.IsMatch cause CPU to reach 100%?

后端 未结 3 1686
执念已碎
执念已碎 2021-02-19 02:13

When using Regex.IsMatch (C#, .Net 4.5) on a specific string, the CPU reaches 100%.

String:

https://www.facebook.com/CashKingPirates/ph         


        
3条回答
  •  隐瞒了意图╮
    2021-02-19 02:29

    Your regex suffers for catastrophic backtracking.You can simply use

    ^http(s)?://([\w.-])+(/[\w ./?%&=-]+)*$
    

    See demo.

    https://regex101.com/r/cK4iV0/15

提交回复
热议问题