D
D
des1roer2016-05-24 16:44:33
C++ / C#
des1roer, 2016-05-24 16:44:33

C# regular expression for ][?

how can i get
[text 1] needed text [text 2]
try

string pat = @"\](*W)\[";
                    Regex r = new Regex(pat, RegexOptions.IgnoreCase);

                    Match m = r.Match(sWinTitle);

                    MessageBox.Show(m.ToString());

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kestik, 2016-05-24
@des1roer

string text = "[текст 1] необходимый текст [текст 2]";

Regex re = new Regex(@"\](.+)\[", RegexOptions.IgnoreCase);
Match m = re.Match(text);

// m.Groups[1].Value будет содержать необходимый вам текст.
// Нулевой элемент массива m.Groups содержит исходный текст.
Console.WriteLine(m.Groups[1].Value);

F
Fat Lorrie, 2016-05-24
@Free_ze

\][^\[]+\[

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question