Skip to content

Instantly share code, notes, and snippets.

@davidfowl
Last active June 22, 2016 01:17
Show Gist options
  • Save davidfowl/6694901 to your computer and use it in GitHub Desktop.
Save davidfowl/6694901 to your computer and use it in GitHub Desktop.
Here's a regex that will max out your CPU (just one)
using System;
using System.Text.RegularExpressions;
namespace RegexFail
{
class Program
{
static void Main(string[] args)
{
var urlPattern = new Regex(@"(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'"".,<>?«»“”‘’]))", RegexOptions.Compiled | RegexOptions.IgnoreCase);
string message = "http://developer.android.com/reference/android/app/Activity.html#onCreateView(android.view.View,%20java.lang.String,%20android.content.Context,%20android.util.AttributeSet)";
foreach (Match m in urlPattern.Matches(message))
{
Console.WriteLine(m.Value);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment