简体   繁体   中英

Regular Expression in C#

i have a string like that:

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

I need to make a Regular Expression that can give me matches as groups, so in my MathCollection I should have

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

Can somebody to help me?

Thanks in advance.

Something like this:

(\[.*?\])

http://regexr.com?2trpv

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

A one liner which gives you an array of the strings you wanted:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM