From ec23a80c1d5de8736d03bedff0d9b50656936db9 Mon Sep 17 00:00:00 2001 From: Chris Johnston Date: Fri, 8 Feb 2019 12:56:29 -0800 Subject: [PATCH] make the Regex static, specify flags --- src/Discord.Net.Webhook/DiscordWebhookClient.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net.Webhook/DiscordWebhookClient.cs b/src/Discord.Net.Webhook/DiscordWebhookClient.cs index 33da596e5..05cf07cfe 100644 --- a/src/Discord.Net.Webhook/DiscordWebhookClient.cs +++ b/src/Discord.Net.Webhook/DiscordWebhookClient.cs @@ -32,7 +32,7 @@ namespace Discord.Webhook : this(webhookUrl, new DiscordRestConfig()) { } // regex pattern to match webhook urls - private const string WebhookUrlRegex = @"^.+.com\/api\/webhooks\/([\d]+)\/([A-Za-z0-9_-]+)$"; + private static Regex WebhookUrlRegex = new Regex(@"^.+.com\/api\/webhooks\/([\d]+)\/([a-z0-9_-]+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); /// Creates a new Webhook Discord client. public DiscordWebhookClient(ulong webhookId, string webhookToken, DiscordRestConfig config) @@ -66,8 +66,7 @@ namespace Discord.Webhook // thrown when groups are not populated/valid, or when there is no match ArgumentException ex() => new ArgumentException(paramName: nameof(webhookUrl), message: "The given webhook Url was not in a valid format."); - var re = new Regex(WebhookUrlRegex); - var match = re.Match(webhookUrl); + var match = WebhookUrlRegex.Match(webhookUrl); if (match != null) { // ensure that the first group is a ulong, set the _webhookId