Regex Functions


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

Easy functions, comments in code.

From: http://www.ilovejackdaniels.com/asp/vbscript-regular-expressions/


Copy this code and paste it in your HTML
  1. Function Regex_Match(strOriginalString, strPattern, blnIgnoreCase)
  2. ' Function matches pattern, returns true or false
  3. ' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
  4. Dim objRegExp : Set objRegExp = New RegExp
  5.  
  6. With objRegExp
  7. .Pattern = strPattern
  8. .IgnoreCase = blnIgnoreCase
  9. .Global = True
  10. End With
  11.  
  12. ereg = objRegExp.test(strOriginalString)
  13. Set objRegExp = Nothing
  14. End Function
  15.  
  16. Function Regex_Replace(strOriginalString, strPattern, strReplacement, blnIgnoreCase, blnGlobal)
  17. ' Function replaces pattern with replacement
  18. ' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
  19. Dim objRegExp : Set objRegExp = New RegExp
  20.  
  21. With objRegExp
  22. .Pattern = strPattern
  23. .IgnoreCase = blnIgnoreCase
  24. .Global = blnGlobal
  25. End With
  26.  
  27. ereg_replace = objRegExp.replace(strOriginalString, strReplacement)
  28. Set objRegExp = Nothing
  29. End Function

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.