Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用split在字符串的开头和/或结尾保留空格_C#_Regex - Fatal编程技术网

C# 如何使用split在字符串的开头和/或结尾保留空格

C# 如何使用split在字符串的开头和/或结尾保留空格,c#,regex,C#,Regex,我目前正尝试使用以下方法将字符串拆分为几段: var output = Regex .Split(input, @"(?<=[)])\s*|\s*(?=[(])") .Where(s => s != string.Empty) .ToList(); var输出=Regex .Split(输入,@)(?当前的(?是的,我添加了一个rextester小提琴链接,IDEONE一直在崩溃。 va

我目前正尝试使用以下方法将字符串拆分为几段:

var output = Regex
                .Split(input, @"(?<=[)])\s*|\s*(?=[(])")
                .Where(s => s != string.Empty)
                .ToList();
var输出=Regex

.Split(输入,@)(?当前的
(?是的,我添加了一个rextester小提琴链接,IDEONE一直在崩溃。
var output = Regex
            .Split(input, @"(\([^()]*\))")
            .Where(s => !string.IsNullOrEmpty(s))
            .ToList();
@"(\((?>[^()]+|(?<c>)\(|(?<-c>)\))*\)(?(c)(?!)))"