Return to Snippet

Revision: 17659
at March 9, 2010 08:54 by wizard04


Updated Code
'****************************************
' Functions to make using regular expressions a bit easier. They're named after the respective PHP function.
' 
' Got these from http://www.addedbytes.com/asp/vbscript-regular-expressions/
'****************************************

function ereg(strOriginalString, strPattern, varIgnoreCase)
	' Function matches pattern, returns true or false
	' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
	dim objRegExp
	set objRegExp = new RegExp
	with objRegExp
		.Pattern = strPattern
		.IgnoreCase = varIgnoreCase
		.Global = True
	end with
	ereg = objRegExp.test(strOriginalString)
	set objRegExp = nothing
end function

function ereg_replace(strOriginalString, strPattern, strReplacement, varIgnoreCase)
	' Function replaces pattern with replacement
	' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
	dim objRegExp
	set objRegExp = new RegExp
	with objRegExp
		.Pattern = strPattern
		.IgnoreCase = varIgnoreCase
		.Global = True
	end with
	newStr = objRegExp.replace(strOriginalString, strReplacement)
	ereg_replace = newStr
	set objRegExp = nothing
end function

Revision: 17658
at March 9, 2010 08:53 by wizard04


Updated Code
'****************************************
' Functions to make using regular expressions a bit easier. They're named after the respective PHP function.
' 
' Got these from http://www.addedbytes.com/asp/vbscript-regular-expressions/
'****************************************/

function ereg(strOriginalString, strPattern, varIgnoreCase)
	' Function matches pattern, returns true or false
	' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
	dim objRegExp
	set objRegExp = new RegExp
	with objRegExp
		.Pattern = strPattern
		.IgnoreCase = varIgnoreCase
		.Global = True
	end with
	ereg = objRegExp.test(strOriginalString)
	set objRegExp = nothing
end function

function ereg_replace(strOriginalString, strPattern, strReplacement, varIgnoreCase)
	' Function replaces pattern with replacement
	' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
	dim objRegExp
	set objRegExp = new RegExp
	with objRegExp
		.Pattern = strPattern
		.IgnoreCase = varIgnoreCase
		.Global = True
	end with
	newStr = objRegExp.replace(strOriginalString, strReplacement)
	ereg_replace = newStr
	set objRegExp = nothing
end function

Revision: 17657
at September 11, 2009 11:53 by wizard04


Initial Code
'got these from http://www.addedbytes.com/asp/vbscript-regular-expressions/

function ereg(strOriginalString, strPattern, varIgnoreCase)
	' Function matches pattern, returns true or false
	' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
	dim objRegExp
	set objRegExp = new RegExp
	with objRegExp
		.Pattern = strPattern
		.IgnoreCase = varIgnoreCase
		.Global = True
	end with
	ereg = objRegExp.test(strOriginalString)
	set objRegExp = nothing
end function

function ereg_replace(strOriginalString, strPattern, strReplacement, varIgnoreCase)
	' Function replaces pattern with replacement
	' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
	dim objRegExp
	set objRegExp = new RegExp
	with objRegExp
		.Pattern = strPattern
		.IgnoreCase = varIgnoreCase
		.Global = True
	end with
	newStr = objRegExp.replace(strOriginalString, strReplacement)
	ereg_replace = newStr
	set objRegExp = nothing
end function

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

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

Initial Title
VBScript Regular Expression Search and Replace Functions

Initial Tags
regex, regexp, ASP

Initial Language
ASP