Hi there, I wonder if somebody could help me here... I am struggling to extract a 'matched' string and wonder if I am missing something simple.
I have the following scenario....
Let's say my code finds a string.... 'abcdefgh -john.smith 1234567 a123-a-123-f the last search, abc, 123 ;'
I am searching this string for the pattern '[a-z]###-[a-z]-###-*'
I know this text appears in the string as 'a123-a-123-f'
I would like to be able to return the matched string value 'a123-a-123-f' to a variable.
If I place a wildcard * in front of the pattern, it will find the text, but obviously everything else in front of it, is there a way that somebody can think of to strip the variable without using the preceding wildcard?
I am not worried about the wildcard on the end of the string as I can strip back to the last space.
I am trying the code shown below, I don't really see why it won't work?!?!? The code itself is working with no errors, it just doesn't match the string.
*****************************
strReader = lcase("abcdefgh -john.smith 1234567 a123-a-123-f the last search, abc, 123 ;")
Dim re As New Regex(Lcase("[a-z]###-[a-z]-###-"))
Dim ma As Match = re.Match(strReader)
If ma.Success Then
' Print out the character position where a match was found.
Console.WriteLine("Found match at position " & ma.Index.ToString())
End If
*****************************
Many thanks for any help you can offer, I hope I have explained it clearly!!
I have the following scenario....
Let's say my code finds a string.... 'abcdefgh -john.smith 1234567 a123-a-123-f the last search, abc, 123 ;'
I am searching this string for the pattern '[a-z]###-[a-z]-###-*'
I know this text appears in the string as 'a123-a-123-f'
I would like to be able to return the matched string value 'a123-a-123-f' to a variable.
If I place a wildcard * in front of the pattern, it will find the text, but obviously everything else in front of it, is there a way that somebody can think of to strip the variable without using the preceding wildcard?
I am not worried about the wildcard on the end of the string as I can strip back to the last space.
I am trying the code shown below, I don't really see why it won't work?!?!? The code itself is working with no errors, it just doesn't match the string.
*****************************
strReader = lcase("abcdefgh -john.smith 1234567 a123-a-123-f the last search, abc, 123 ;")
Dim re As New Regex(Lcase("[a-z]###-[a-z]-###-"))
Dim ma As Match = re.Match(strReader)
If ma.Success Then
' Print out the character position where a match was found.
Console.WriteLine("Found match at position " & ma.Index.ToString())
End If
*****************************
Many thanks for any help you can offer, I hope I have explained it clearly!!
Last edited: