Example: Using Regular Expression in VBScript

ATTENTION: This forum is no longer active. Please navigate to our new support site at https://support.starfishetl.com/
Viewing 1 posts (of 1 total)
srijanapokharel
User - Author
Post count: 27
#1

I have been trying to implement regular expression in VB Script.

  1. Function ScriptedField
  2.    Dim regEx, objMatch, objMatches, strReturn
  3. 	Dim strPattern="This is test String for Reg Exp"
  4. 	Set regEx = New RegExp
  5. 	regEx.Pattern = [a-z]
  6. 	regEx.IgnoreCase = True
  7. 	regEx.Global = True
  8.    strReturn = strReturn & vbCRLF

I have tried it this way and this script looks incomplete. Will you please post a simple example of using the Regualr Expression?

Comments (1)

Aron Hoekstra's picture Aron Hoekstra
Administrator
Post count: 2
#2

This should work. This sample will replace whitespace from a string and replace it with a single quote.

  1. Function ScriptedField
  2. 	Set regEx = New RegExp
  3. 	regEx.Global = true
  4. 	regEx.IgnoreCase = True
  5. 	regEx.Pattern = "^[ t]+|[ t]+$"
  6.  
  7. 	' Input a string to test our replace functionality:  
  8. 	strText = "   Starfish Regular Expression Test    " 
  9.  
  10. 	' Call Replace method of the regular expression: 
  11. 	' the $1 means place the matching text here
  12. 	strReturn = regEx.Replace(strText, "'")
  13.  
  14.         ScriptedField=strReturn
  15. End Function

Returns:
'Starfish Regular Expression Test'

Log in to post comments
Viewing 1 posts (of 1 total)

Forum Login

Login or sign up for our forums to connect to the user community.

Reply

You must log in to post.

Not a Member? Register.