G
Guest
I have a Perl background, so some of what I know in other contexts is
probably getting in the way of what I need to learn now. With that
said, I'm having a problem getting my regex to work as I expect. I
have a string value like "John Q Public" in a textbox called "Name",
and I want to use the regex to split out first name and last name.
Here's what I've coded:
Dim FirstName As String
Dim LastName As String
If Regex.IsMatch(NameTextBox.Text, "(^\w+)\s(\w\s)?(\w+)$")
Then
FirstName = $1
LastName = $3
End If
but the the VB 2005 Express IDE is telling me the $ in $1 and $2 are
invalid characters.
My hunch is that $1 and $2 only make sense inside the Regex namespace,
but I'm not sure what my next step should be. Do I need to create a
Match object to access the values? All the examples I've found on the
web seem to assume that the only reason you'd want to extract values is
to re-arrange them in a replace, but that's not what I have in mind.
probably getting in the way of what I need to learn now. With that
said, I'm having a problem getting my regex to work as I expect. I
have a string value like "John Q Public" in a textbox called "Name",
and I want to use the regex to split out first name and last name.
Here's what I've coded:
Dim FirstName As String
Dim LastName As String
If Regex.IsMatch(NameTextBox.Text, "(^\w+)\s(\w\s)?(\w+)$")
Then
FirstName = $1
LastName = $3
End If
but the the VB 2005 Express IDE is telling me the $ in $1 and $2 are
invalid characters.
My hunch is that $1 and $2 only make sense inside the Regex namespace,
but I'm not sure what my next step should be. Do I need to create a
Match object to access the values? All the examples I've found on the
web seem to assume that the only reason you'd want to extract values is
to re-arrange them in a replace, but that's not what I have in mind.