Posted By

wizard04 on 09/11/09


Tagged

regex regexp ASP vbscript


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

nelda751
ckayra
benrudolph


VBScript Regular Expression Search and Replace Functions


 / Published in: ASP
 

URL: http://www.addedbytes.com/asp/vbscript-regular-expressions/

Functions to make using regular expressions a bit easier. They're named after the respective PHP function.

  1. '****************************************
  2. ' Functions to make using regular expressions a bit easier. They're named after the respective PHP function.
  3. '
  4. ' Got these from http://www.addedbytes.com/asp/vbscript-regular-expressions/
  5. '****************************************
  6.  
  7. function ereg(strOriginalString, strPattern, varIgnoreCase)
  8. ' Function matches pattern, returns true or false
  9. ' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
  10. dim objRegExp
  11. set objRegExp = new RegExp
  12. with objRegExp
  13. .Pattern = strPattern
  14. .IgnoreCase = varIgnoreCase
  15. .Global = True
  16. end with
  17. ereg = objRegExp.test(strOriginalString)
  18. set objRegExp = nothing
  19. end function
  20.  
  21. function ereg_replace(strOriginalString, strPattern, strReplacement, varIgnoreCase)
  22. ' Function replaces pattern with replacement
  23. ' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
  24. dim objRegExp
  25. set objRegExp = new RegExp
  26. with objRegExp
  27. .Pattern = strPattern
  28. .IgnoreCase = varIgnoreCase
  29. .Global = True
  30. end with
  31. newStr = objRegExp.replace(strOriginalString, strReplacement)
  32. ereg_replace = newStr
  33. set objRegExp = nothing
  34. end function

Report this snippet  

You need to login to post a comment.