Bryuk Bryuk - 2 months ago 5
Vb.net Question

Regex to get all words from string, sepatated by spaces and any symbols

I have some string, for example like this

Dim pattern As String = *** I need Regex here ***
Dim input As String = " John, Smith .Jr: Superman Inc!"
Dim SearchedResult() As String = Regex.Split(input, pattern, RegexOptions.IgnoreCase)


In
SearchedResult()
I want to have all words without any Symbols and spaces, like:

John
Smith
Jr
Superman
Inc


I'm not so good in Regex, but I need that really quick :) Please, any help on that

Answer

Simply try with \w that match any word character [a-zA-Z0-9_]

\w+

Here is demo and tested at regexstorm


If you want to exclude underscore and digit then try

\b[a-zA-Z]+\b

where \b is treated as word boundary

It is tested at regexstorm

Comments