我有一個這樣的字符串:正則表達式
[variable = value][variable2=value2][Some text inside]
我需要做,可以給我的羣相匹配,所以在我MathCollection我應該有
matches[0] = [variable = value]
matches[1] = [variable2=value2]
matches[2] = [Some text inside]
正則表達式有人可以幫助我嗎?
在此先感謝。
我有一個這樣的字符串:正則表達式
[variable = value][variable2=value2][Some text inside]
我需要做,可以給我的羣相匹配,所以在我MathCollection我應該有
matches[0] = [variable = value]
matches[1] = [variable2=value2]
matches[2] = [Some text inside]
正則表達式有人可以幫助我嗎?
在此先感謝。
Regex getStuff = new Regex("(\[.*?\])");
MatchCollection matches = getStuff.Matches(inputString);
嗯,manojlds說的。 – FlyingStreudel 2011-05-26 20:56:50
它工作正常,我這樣做,它只需要在構造函數之前的第一個「 謝謝! – Mallok 2011-05-27 17:51:10
一個一個襯墊,讓你你想要的字符串數組:
var strings = Regex.Matches(input, @"(\[.*?\])").Cast<Match>().Select(match => match.ToString()).ToArray();
謝謝,我已經試過了但它沒有奏效,因爲C#中的正則表達式是不同的。 – Mallok 2011-05-27 17:32:26
@Mallok你是什麼意思? – manojlds 2011-05-27 17:35:15
對不起,我試了一遍,它工作正常,我這樣做: '正則表達式reg =新的正則表達式(@「(\ [。*?\])」);' 非常感謝。 – Mallok 2011-05-27 17:48:18