Introduction:
In this article we split a large whitespace using regular expression

Normally if we use normal split function using white space, it separate by each white space character..But by using regular expression, its very easy to split string using whit space..
Here I illustrate an example by code…
We have string like this…
Code:
Dim str As String = "1234567            12345         678594"

We want to separate only the numbers, In that case normal split function won’t help us…For that we for or regex expression.
Code:

Dim str As String = "1234567            12345         678594"
        Dim str1 As String()
        Dim rgs As Regex = New Regex("  +")
        str1 = rgs.Split(str)

The result the sr1 contains only 3 array. By using this regex pattern (“    +”), it easy to avoid the extra white space.

I hope you enjoy this method to split a string in large white space……….


Hi..
Here I share the regular expression code for India mobile number and landline number
For Mobile Number
^9\d{9}$

For Landline Number

^[0-9]\d{2,4}-\d{6,8}$

10:22 AM

Regular Expression for separate a string

Posted by vijay


HI..Here I have to share an regular expression usage for split text from string…..Normally we can split a string some character .In some cases we have mix with number of characters…For that situation we can use regex expression to separate a string….
Here some example…
(test1) “"test2"” ANY(test) AND(test) (raj:test5 AND Test=test6) &animaltiger&
For this word we want to separate as each word we use reular expression
(test1)
“"test2"”
 ANY(test)
AND(test)
(raj:test5 AND Test=test6)
&animaltiger&
By using regex we can separate like above….
The Code as follows…….
VB CODE
Dim result As New List(Of String)
        Dim str As String
        str = "(test1) ""test2"" ANY(test) AND(test) (raj:test5 AND Test=test6) &animaltiger&"
        Dim t As MatchCollection = Regex.Matches(str, "[""].+?[""]|[^\s]*?[(].+?[)]|[&].+?[&]")
        For Each itm As Match In t
            result.Add(itm.Value)
        Next
C# code
  List<string> result = new List<string>();
            string s = @"(test1) ""test2"" ANY(test) AND(test) (raj:test5 AND Test=test6) &animaltiger&";
           
            MatchCollection t = Regex.Matches(s, @"[""].+?[""]|[^\s]*?[(].+?[)]");
           
            foreach (Match  itm in t)
            {
                result.Add(itm.Value);
            }
I hope this one helpful to all