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

后端 未结 3 1708
执念已碎
执念已碎 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:20

    I suggest you to check http://regexr.com/ website, to test your regular expression.

    The corrected version of your regular expression is this:

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

    It also has 3 groups:

    1. group1=Main url (for example: facebook.com)
    2. group2=Sub urls (for example: /CashKingPirates/photos/a.197028616990372.62904.196982426994991/1186500984709792/
    3. group3=Variables (for example: ?type=1&permPage=1)

    Also remember for checking actual character of dot (.) in your regular expression you must use \. not .

提交回复
热议问题