using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"# Start defining
(?(DEFINE)
(?<XSEP>\s*[xх\*\-\s]?\s*)
(?<MARGIN>(?:\.\d)?)
(?<RADIUS>r?[12]\d(?&MARGIN))
(?<J>(?:1[01]|[4-9])(?&MARGIN)j?)
(?<DIAM>
\b
(?:
(?&RADIUS)(?:\s*\/\s*(?&J))?
|
(?&J)(?&XSEP)(?&RADIUS)
)
\b
)
(?<PCD>\b(?:[pb]cd\s*)?[34568](?&XSEP)(?:98|[12]\d{2})(?&MARGIN)\b)
(?<ET>(?:(?:et|ет)\s*)?\-?\d+(?&MARGIN)\b)
(?<CB>\b(?:(?:цо|cb|d(?:ia)?)\s*)?\d{2,3}(?&MARGIN)\b)
)
# End defining
(?:
(?<diam>(?&DIAM))
|
(?<pcd>(?&PCD))
|
(?<et>(?&ET))
|
(?<cb>(?&CB))
)";
string input = @"r22 pcd 4x108 ET 45.5 ЦО 58.5
15 /5.0j 6*108 et45 ЦО 58.5
15/ 5.0j 4x108 -45.5 58.5
pcd 4x138 15/5.0j ET58.5 ЦО45
ЦО45.5 ET58.5 19 pcd 4x 108
r15/5.6j pcd 5х112 ET60 CB66
et50 r15/5 5х112 ET60 d66
r15/5 pcd 5*112 ET60 dia 66
5.6j x 15.5 pcd 5 х 112 ет -60 CB66
5x15.5 5х112.5 ET60 CB66
250/50 r16";
RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.CultureInvariant;
foreach (Match m in Regex.Matches(input, pattern, options))
{
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