Split text at the first instance of a letter
I have a bunch of product sku's that look like:
abc234
asdf234324
adc234-b
result:
abc 234
asdf 234324
adc 234-b
开发者_开发技巧
I want to split the text at the first instance of a letter.
When I say split, basically I want to have access to both parts of the text, maybe in an array?
What's the best way to do this?
^([a-z]+)(.*)
The first capture group will have the alpha-only prefix, the second capture group will have everything else.
Here is a code sample to go along with @Dav's answer.
List<string> list = new List<string>()
{
"abc234",
"asdf234324",
"adc234-b"
};
Match m;
foreach (string s in list)
{
m = Regex.Match(s, "^(?<firstPart>[a-z]+)(?<secondPart>(.+))$");
Console.WriteLine(String.Format("First Part = {0}", m.Groups["firstPart"].Value));
Console.WriteLine(String.Format("Second Part = {0}", m.Groups["secondPart"].Value));
}
精彩评论