using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\b([A-Z]+)0(?=\d{3}\b)";
string substitution = @"$1";
string input = @"SK0498 should return SK498 (total digits = 4 = omit the single leading zero)
AA007 should still return AA007 (because the leading zeros are double, and total digits is only 3)
UA2138 returns UA2138 (no leading zeros involved)
BA023 should return BA023 (keep the zero because total number of digits is only 3), however BA0234 should return BA234 (total digits is 4 with a single leading zero that should be omitted).
AA0007";
RegexOptions options = RegexOptions.Multiline;
Regex regex = new Regex(pattern, options);
string result = regex.Replace(input, substitution);
}
}
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