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

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

String: https://www.facebook.com/CashKingPirates/photos/a.197028616990372.62904.196982426994991/1186500984709792/?type=1&permPage=1

Pattern:

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

Full code:

Regex.IsMatch(
                "https://www.facebook.com/CashKingPirates/photos/a.197028616990372.62904.196982426994991/1186500984709792/?type=1&permPage=1",
                @"^http(s)?://([w-]+.)+[w-]+(/[w- ./?%&=])?$");

I found that redacting the URL prevents this problem. Redacted URL: https://www.facebook.com/CashKingPirates/photos/a.197028616990372.62904.196982426994991/1186500984709792

But still very interested in understanding what causes this.


Source: regex

Leave a Reply