VBScript正则表达式搜索和替换函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VBScript正则表达式搜索和替换函数相关的知识,希望对你有一定的参考价值。

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

以上是关于VBScript正则表达式搜索和替换函数的主要内容,如果未能解决你的问题,请参考以下文章

Python爬虫编程思想(35):用正则表达式搜索替换和分隔字符串

vbscript正则表达式,替换两个字符串

43 正则中用sub和subn函数搜索与替换 使用split函数分隔字符串 练习题

JavaScript 正则表达式

php正则表达式的匹配与替换

在 Excel 中使用正则表达式进行查找与替换