Check an example with a single string:
string shape = "C100X11";
Match m = Regex.Match( shape, @"^(C\d+)X(\d+(?:\.\d+)?)$" );
if( m.Success )
{
string first_part = m.Groups[1].Value;
string last_part = m.Groups[2].Value;
. . .
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I need to parse strings like these string[] steelShapes = new string[] { "C100X11", "C100X8", "C10X15.3", "C10X20", "C12X20.7", "C150X16", "C15X40", "C150X19" }; I need to separate them into two strings, before and after the X. I know could split the strings at the X. However, I tried to write an regex expression to capture two groups. I have been able to capture either the first or the last part using these two separate expressions. patternOne = @"(C\d+(?=X))" patternTwo = @"(?:((?<=X)\d+)?|((?<=X)\d+.\d+))?$" What I can't do is to put them together to get the two groups. Can someone please explain how to put them together to make it work?
Check an example with a single string:
string shape = "C100X11";
Match m = Regex.Match( shape, @"^(C\d+)X(\d+(?:\.\d+)?)$" );
if( m.Success )
{
string first_part = m.Groups[1].Value;
string last_part = m.Groups[2].Value;
. . .
}