IsLike Function:
Compares a string to a regular expression.
Description:
The IsLike function compares a string using a regular expression and returns True if the regular expression matches the input string or False if the pattern doesn't match. There are two required arguments, string and pattern. String is the string to compare. Pattern is the regular expression to apply to the string. Returns Null if error handling is enabled and a problem is encountered during comparison.
Syntax:
boolean = IsLike(string, pattern)
Example:
<%
'--- IsLike returns True to indicate a pattern match. response.write IsLike("Livio Siri", "[A-Z]\D\D\D\D\s[A-Z]\D\D\D")
'--- IsLike returns False to indicate no pattern match. response.write IsLike("Livio Siri", "B[^i]")
%>
ASP Source Code:
<%
Private Function IsLike(byVal String, byVal Pattern) Dim a, b, boolErr On Error Resume Next Set a = New RegExp If Err Then boolErr = True End If On Error GoTo 0 If boolErr then Err.Raise 5108, "IsLike Function", "This function uses " & _ "the RegExp object and requires the VBScript " & _ "Scripting Engine Version 5.1 or higher." IsLike = Null Exit Function End If a.Pattern = pattern a.IgnoreCase = false a.Global = true Set b = a.Execute(String) if b.Count > 0 then IsLike = True else IsLike = False end if Set b = nothing Set a = Nothing End Function
%>
|