Here is the pattern I use for now:
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>();
With this I retrieve an array of strings, on item for each word and one item for each punctuation character.
What I'd like to achieve now is grouping queued punctuation chars in only one item, i.e. for now if there are three dots one after the other, I get three items in my array each containing a dot. Ultimately I'd like to have one item with three dots (or any other punctuation char for that matter).
Try this regex:
^(\s+|\d+|\w+|[^\d\s\w]+)+$

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With