1

I am trying to split this string " "109491: Navy/Red115138: Navy/Light Grey" in Colour Code and colour name. The numeric is colour-code and the string including \ is color name. I have tried this regular expression "(?<Alpha>[a-zA-Z]*)(?<Numeric>[0-9]*)" but it did not work as desired . Some times it is returning empty in Colour Code.

Thanks

4
  • What do you mean - sometimes? For what input specifically? Commented Feb 14, 2014 at 11:52
  • kindly put the string that you want to split Commented Feb 14, 2014 at 11:55
  • Actually i am getting the above mentioned string from the webservice but i need to store the colour code and color name seperately for specific reason. Commented Feb 14, 2014 at 11:56
  • @SaddamAbuGhaida "109491: Navy/Red115138: Navy/Light Grey" this is the string Commented Feb 14, 2014 at 11:57

2 Answers 2

1

Try something like this:

(?:(\d+):\s([^\d]+))+?

This will capture the numbers and text as separate captures.

For example:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Where does the screenshot you posted come from?
1

Simply use this:

(\d+[^\d]+)

It is "select numbers.. then anything else that isn't a number". So it matches like this:

109491: Navy/Red115138: Navy/Light Grey
|______________||______________________|

E.g:

var str = "109491: Navy/Red115138: Navy/Light Grey";
var matches = new List<string>();

foreach (Match match in Regex.Matches(str, @"(\d+[^\d]+)")) {
    matches.Add(match.Value);
}

// matches[0] = 109491: Navy/Red
// matches[1] = 115138: Navy/Light Grey

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.