F
F
Fairlancer2016-01-11 00:50:57
Programming
Fairlancer, 2016-01-11 00:50:57

How to extract values ​​from a variable using C# regex?

In general, there is a line like this:
text:text2:text3
In this case, the first "text" always has the same length, the second "text2" is constantly changing, the third "text3" too.
You need to extract these three values, bypassing the ":" separators.
PS Tried like this:

Regex myReg = new Regex("\\<text>:<text2>:<text3>\\", RegexOptions.IgnoreCase);
            foreach (Match m in myReg.Matches(TextSelected))
            {
               
            text = m.Groups["text"].Value;
            text2 = m.Groups["text2"].Value;
            text3 = m.Groups["text3"].Value;

            }

In theory, from the point of view of a person, everything is logical, but apparently the stone has a different opinion ... Please help, I have been studying C # for 3 days, but the most difficult thing for me is regular expressions. I don’t understand how they work, and that’s it. If someone teaches me - a box of cold beer and a drain of any haida on a special from me. forums.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2016-01-11
@kursorik2

^(?<text>[^:]*):(?<text2>[^:]*):(?<text3>[^:]*)$
I don't know what source you looked at, everything is very clear on MSDN: https://msdn.microsoft.com/en-us/library/bs2twtah(...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question