Select Page
Codoid Blog

Splitting a String Using Regular Expression

Being a leading QA Company, we write blogs on all prominent software testing topics and tools using our real-world experience. So stay sharp by subscribing to our Newsletter.

.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.

Comments(0)

Submit a Comment

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

Talk to our Experts

Amazing clients who
trust us


poloatto
ABB
polaris
ooredo
stryker
mobility