C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Input:
('BH','BAHRAIN','Bahrain','BHR','048')
Fields:
BH
BAHRAIN
Bahrain
BHR
048
Also: The question mark specifies that the match should be as short as possible. This means two entries will never be matched as one.
VB.NET program that uses Regex.Matches with quotes
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
' The input string.
Dim value As String = "('BH','BAHRAIN','Bahrain','BHR','048')"
' Match data between single quotes hesitantly.
Dim col As MatchCollection = Regex.Matches(value, "'(.*?)'")
' Loop through Matches.
For Each m As Match In col
' Access first Group and its value.
Dim g As Group = m.Groups(1)
Console.WriteLine(g.Value)
Next
End Sub
End Module
Output
BH
BAHRAIN
Bahrain
BHR
048
Note: You would have to specify all non-matching characters such as the parentheses, quotes, and commas.