Reputation: 83
How can I get only the Name?
"Hello Name!"
Dim r As New Regex("Hello (.*)! :)")
Dim matches As MatchCollection = r.Matches(Chat)
For Each m As Match In matches
MsgBox("Hi " & m.ToString & " and welcome back!")
Next
(Chat is the last Chatmessage)
Upvotes: 1
Views: 471
Reputation: 39365
Why don't you do a string replace for Hello and the ! as you know these are fixed??
I don't know VB, but a REGEX in other language should be Hello (\S+)!
Upvotes: 1
Reputation: 16878
To get only name, you should use Groups
. And if you really want to match :)
, you must escape )
by using \
:
Dim Chat As String = "Hello Name!"
Dim r As New Regex("Hello (.*)! :\)")
Dim matches As MatchCollection = r.Matches(Chat)
For Each m As Match In matches
m.Groups(1).Value
Next
Upvotes: 3