using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(X(-?\d+(?:\.\d+)?))?\s*(Y(-?\d+(?:\.\d+)?))?";
string input = @"N14 X411 Y279.05
N15 G2 X33 Y280.4 I.001 J4.00
N16 G1 X408 Y280.4
N17 G2 X402.3 Y280.09 I-3 J2.65
N18 G1 X402.3 Y280.09
N19 G2 X402.09 Y285.79 I2.7 J2.95
N20 G1 X402.09 Y285.79
N3 G40 Y6000
N3 G40 X-6000";
RegexOptions options = RegexOptions.Multiline;
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