I am searching for a RegularExpression to split a text in it words.
I have tested
Regex.Split(text, @"\s+")
But this gives me for example for
this (is a) text. and
this
(is
a)
text
and
But I search for a solution, that gives me only the words – without the (, ), . etc.
It should also split a text like
end.begin
in two words.
You’re probably better off matching the words rather than splitting.
If you use
Split(with\Was Regexident suggested), then you could get an extra string at the beginning and end. For example, the input string(a b)would give you four outputs:"","a","b", and another"", because you’re using the(and)as separators.What you probably want to do is just match the words. You can do that like this:
Then you’ll get just the words, and no extra empty strings at the beginning and end.