using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(\[\d{3,5} ?x ?\d{3,5}\])";
string input = @"Should match:
Hey guys check out this awesome hi-def picture! [320x480]
[F]irst time here plz be nice [6969x6969]
Spaces around the x [123 x 456]
herp derp durr (smallest dimensions that will match) [100x100]
Check out this massive 2.1 jiggapixel image of the entire USA in high detail! (highest dimensions that will match) [99999x99999]
Should not match:
Please go to this spammy site and buy shit so we can steal your credit card (no tag)
Letters in the tag [i234x5678]
Dimension too small [99 x 123]
Dimension too big [100000 x 123]
";
foreach (Match m in Regex.Matches(input, pattern))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx