How do you define "first,last and middle part of the string" in
i want to get the "Lebron","King","James" separately .
Look for common traits shared by the result that you want and I noticed they are double-quoted individually, then call Regex to extract them. See example:
Imports System
Imports System.Text.RegularExpressions
Public Module Module1
Public Sub Main()
Dim str As String = "i want to get the ""Lebron"",""King"",""James"" separately."
Console.Write("The sentence is: ")
Console.WriteLine(str)
Dim pattern As String = "(?<="")[^,""]+(?="")"
Console.Write("The Regex pattern is: ")
Console.WriteLine(pattern)
showMatch(str, pattern)
End Sub
Sub showMatch(ByVal text As String, ByVal expr As String)
Dim mc As MatchCollection = Regex.Matches(text, expr)
Dim m As Match
Console.WriteLine("The matched are as follows: ")
For Each m In mc
Console.WriteLine(m)
Next m
End Sub
End Module
The result as shown:
The sentence is: i want to get the "Lebron","King","James" separately.
The Regex pattern is: (?<=")[^,"]+(?=")
The matched are as follows:
Lebron
King
James
Learn
The 30 Minute Regex Tutorial[
^]