tags:

views:

20

answers:

1

how can i split them into an array of items, i.e. array[0] = "ABC ", array[1] = "YXYZ", array[2] = " " array[3]= " 123 " ...

Regular Expression Gurus! Help!

Don't care about performance, only code terseness, i.e. nifty unreadable code is totally fine.

EXTRA CREDIT:

I really want to do this --> everything in [ ] needs to basically formatted in a specific way. The caveat is that I can't do a regex replace, so I have to put into a collection, and somehow mark that I'm in plain text mode or decoration mode. I'm thinking I'll put this all into a queue or stack, and put a null in the stack to identify marking plain text vs. decoration regions.

any ideas?

A: 

Do you need to use regex for this?

Using the string split function:

       Dictionary <string, bool> theDict = new Dictionary<string,bool> (); 
       string input= @"abc [xyz] [123] asdasd";
       string[] a2;
       string[] a1 = input.Split('[');
       for (int i = 0; i< a1.Length; i++)
       {
           a2 = a1[i].Split(']');
           if (a2.Length == 1)
               theDict.Add(a2[0], false);  // no special formatting
           else
           {
               theDict.Add(a2[0], true);   // special formatting

               theDict.Add(a2[1], false);
           }
       }

will get you the result you are asking for.

Lill Lansey