TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET Regex.Matches Quote Example

Use the Regex.Matches Function on quoted String data. Ensure quotes are handled.
Regex.Matches Quote. Regex.Matches can handle quoted data. We parse a String containing fields inside quotes in VB.NET. Special care must be taken with the expression pattern. We show an example of parsing a textual list.Regex.MatchRegex.Matches
Input: ('BH','BAHRAIN','Bahrain','BHR','048') Fields: BH BAHRAIN Bahrain BHR 048
Example. To begin, the RegularExpressions namespace must be used in an Imports directive. Next, we call Regex.Matches with a pattern that means we want zero or more characters inside single quotes. The inner part is reluctantly continued.

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
There are definitely alternative methods you can use to accomplish this same task. A simple for-loop that appends the substrings to a List would probably be fastest. The Regex.Split method could be called.Regex.SplitFor Each, For

Note: You would have to specify all non-matching characters such as the parentheses, quotes, and commas.

Summary. We extracted substrings from inside certain characters such as quotes. This approach is not the fastest. But it is fairly simple and straightforward. The Regex pattern can be changed as your requirements change as well.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf