I was going to suggest that earlier, however alot of it will depend on what the initial string may look like. If for example you know its going to be a list of colours then it'll work ok. But IndexOf will pick up 'red' from say 'hatred' or 'rediculous' you could always put spaces either side but that will cause trouble if you have any punctuation in the input string.Nerseus said:Does it have to be regex? Sounds like you just want IndexOf twice?
-ner
If contains works stick with it, theres no point in making something more complicated than it needs be.nbrege said:How do I use IndexOf? I'm not familiar with it. I'm currently using .Contains twice, but I thought maybe a regex would be better.
string input = "this is the string I want to test for red and blue";
if(input.IndexOf("red") != -1 && input.IndexOf("blue") != -1)
{
// the string contains both values
}
That was pure wizardry! Wow, the word boundry escape makes for an easy, clean regex. I didn't know about that one...awesome find.marble_eater said:The word boundary escape is pretty magical.