RegEx: Adding an "OR" condition to an existing expression

G

Guadala Harry

The following function, SplitTheString(), splits a string based on a flag
that is like this:
{Flag1:whateverHere}
Note that the "whateverHere" part can be any character - and at least one
character.

I simply want to extend this RegEx to do the same job - but to do it based
on an additional possible flag:
{Flag2:whateverHere}

So, the split would be based on {Flag1:whateverHere} OR {Flag2:whateverHere}


public static string[] SplitTheString(string inString) {
Regex r = new Regex("({Flag1:.+?})"); // Split on hyphens.
string[] sa = r.Split(inString);
for(int i=0; i< sa.Length; i++) {
sa = sa.Trim();
}
return sa;
}

Thanks to William Stacey for the initial version of this Split() function.

-GH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top