Splitting a String Using Regular Expression - Codoid
Select Page
Codoid Blog

Splitting a String Using Regular Expression

Irrespective of the business that your client is in, marketing is an integral part of their operations. In fact, in this day and age of social.

.Net Regular Expression engine is more powerful than VBScript Regular Expression engine. RegEx is one of the classes of .Net Regular Expression engine. Using the Split method available in RegEx class, we can split a string with Regular Expression pattern. Let us see the implementation below.

Code

Dim oRegex,oArrayList

'Creating instance for RegEx
Set oRegex=DotNetFactory.CreateInstance("System.Text.RegularExpressions.Regex","","")

'Creating instance for ArrayList
'this is required to hold the elements since Split method returns String array. 
Set oArrayList=DotNetFactory.CreateInstance("System.Collections.ArrayList","")

'Splitting the string with Regular Expression
Set oArrayList=oArrayList.Adapter(oRegex.Split("quick test professional", "W+"))

'Displaying the elements
Msgbox oArrayList(0)
Msgbox oArrayList(1)
Msgbox oArrayList(2)

Set oRegex=Nothing
Set oArrayList=Nothing
  

Synopsis

This method is very useful whenever we need to split a string with Regular Expression pattern.

Note: Since ‘RegEx’ Split method returns String array, VBScript Array cannot hold the elements which are returned by this Split method.

Written By

Submit a Comment

Your email address will not be published. Required fields are marked *


.Net Regular Expression engine is more powerful than VBScript Regular Expression engine. RegEx is one of the classes of .Net Regular Expression engine. Using the Split method available in RegEx class, we can split a string with Regular Expression pattern. Let us see the implementation below.

Code

Dim oRegex,oArrayList

'Creating instance for RegEx
Set oRegex=DotNetFactory.CreateInstance("System.Text.RegularExpressions.Regex","","")

'Creating instance for ArrayList
'this is required to hold the elements since Split method returns String array. 
Set oArrayList=DotNetFactory.CreateInstance("System.Collections.ArrayList","")

'Splitting the string with Regular Expression
Set oArrayList=oArrayList.Adapter(oRegex.Split("quick test professional", "W+"))

'Displaying the elements
Msgbox oArrayList(0)
Msgbox oArrayList(1)
Msgbox oArrayList(2)

Set oRegex=Nothing
Set oArrayList=Nothing
  

Synopsis

This method is very useful whenever we need to split a string with Regular Expression pattern.

Note: Since ‘RegEx’ Split method returns String array, VBScript Array cannot hold the elements which are returned by this Split method.