C# How to split (A:B=C)* using regex? -


It is believed that there is a very simple question, but I can not find the right solution. The format is a string:

  a: b = c, d: e = f; G: E = H; ...  

While A, B and C are alphanumeric (as well as upper cases may be reduced) A and B are length 1+, C can be empty.

I thought I would use something on the pattern of

  ((?? Lt; A & gt). +): (? & Lt; b & Gt;.) = (? & Gt;;) *)  

But I do not see how to match it. How do I get results of related matches so that I appreciate a bit code sample.

I would be happy if you can give me a hint.

You match the letters of letters instead of \ w Can use to , after all that matches, you can try to capture a match at a time:

  (? & Lt; A & gt; \ w +): (? & Lt; B & gt; \ w =) = (? & Lt; C & gt; \ w *);  

Here's a small example:

  Reggae Regex = New Reggae ("(? & Lt; A & gt; \\ w +): (? & Lt; B & gt; \\ w +) = (& lt;? C & gt; \\ w *); "); String testing = "a: b = c; d: e = f; g: e = h"; // All Match Match Matching MC = regex.Matches (test); Forester (Match M in MC) {Console.WriteLine ("A = {0}", M. Group ["A"]. Value); Console.light line ("b = {0}", m group ["b"]. Value); Console.light line ("c = {0}", m group ["c"]. Value); }  

Note : There are several tools that allow you to experiment with regular expressions and provide some help; I personally prefer - try it, it will be very useful for learning.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -