tags:

views:

163

answers:

2

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?

+3  A: 
^([a-z]+)(.*)

The first capture group will have the alpha-only prefix, the second capture group will have everything else.

Amber
+2  A: 

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));
}
thedugas
Assumes that the left and right part are 1 or more chars. Probably a good thing, but unspecified by OP.
spender