簡體   English   中英

C# 中的正則表達式

[英]Regular Expression in C#

我有一個這樣的字符串:

[variable = value][variable2=value2][Some text inside]

我需要制作一個正則表達式,它可以給我作為組匹配,所以在我的 MathCollection 中我應該有

matches[0] = [variable = value]
matches[1] = [variable2=value2]
matches[2] = [Some text inside]

有人可以幫助我嗎?

提前致謝。

像這樣的東西:

(\[.*?\])

http://regexr.com?2trpv

Regex getStuff = new Regex("(\[.*?\])");
MatchCollection matches = getStuff.Matches(inputString);

一個襯里,它為您提供所需的字符串數組:

var strings = Regex.Matches(input, @"(\[.*?\])").Cast<Match>().Select(match => match.ToString()).ToArray();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM