SplitRegExp Function:
Uses a regular expression to split a string into an array of elements.
Description:
Allows a programmer to split a string into an array of elements using a regular expression which defines the string which is splitting each element of the string to be turned into an array.
Syntax:
arrayOfStrings = SplitRegExp(stringInput, stringPattern, boolIgnoreCase)
Example:
<%
dim s, arr, element
s = "grgrg~|~item2bcs~|~item3~|~item4~|~d~|~sds" arr = SplitRegExp(s, "\~\|\~", true) response.write s & "<BR><BR>" for each element in arr response.write element & "<BR>" next
'returns: ' ' "grgrg~|~item2bcs~|~item3~|~item4~|~d~|~sds" ' ' "grgrg" ' "item2bcs" ' "item3" ' "item4" ' "d" ' "sds"
%>
ASP Source Code:
<%
function SplitRegExp(byval sInput, byval sPattern, byval bIgnoreCase) dim re, matches, match, hStart, hEnd, i
Set re = new regexp re.pattern = sPattern re.ignorecase = bIgnoreCase re.global = true
if not re.test(sInput) then splitregexp = array(sInput)
set re = nothing exit function end if
set matches = re.execute(sInput) hStart = 0 redim arr(matches.count) i = 0 for each match in matches hEnd = match.firstindex arr(i) = mid(s, hStart+1, hEnd - hStart) hStart = match.firstindex + match.length i = i + 1 next arr(ubound(arr)) = mid(s, hStart+1) set matches = nothing Set re = nothing splitregexp = arr end function
%>
|