【发布时间】:2013-12-25 23:21:22
【问题描述】:
这是我现在使用的模式:
string pattern = @"^(\s+|\d+|\w+|[^\d\s\w])+$";
Regex regex = new Regex(pattern);
if (regex.IsMatch(inputString))
{
Match match = regex.Match(inputString);
foreach (Capture capture in match.Groups[1].Captures)
{
if (!string.IsNullOrWhiteSpace(capture.Value))
tmpList.Add(capture.Value);
}
}
return tmpList.ToArray<string>();
通过这个,我检索了一个字符串数组,每个单词的项目和每个标点符号的项目。
我现在想要实现的是仅将排队的标点符号分组在一个项目中,即现在如果一个接一个地有三个点,我会在我的数组中得到三个项目,每个项目都包含一个点。最终我想要一个带有三个点的项目(或任何其他标点符号)。
【问题讨论】:
标签: c# regex regex-group