VBScript Regular Expression Search and Replace Functions


/ Published in: ASP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.