입력된 문자열이 지정된 정규편식에 부합하는지 체크하는 함수
Function matchPattern(ByVal strMatchPattern, ByVal strPhrase)
ON ERROR RESUME NEXT
Err.Clear
Dim objRegEx
Dim Matches
Dim intResultsCount
intResultsCount = 0
Set objRegEx = New RegExp
If (NOT IsObject(objRegEx)) Then
WScript.Echo "L_ERROR_CHECK_VBSCRIPT_VERSION"
End If
objRegEx.Global = True
objRegEx.IgnoreCase = True
objRegEx.Pattern = strMatchPattern
Set Matches = objRegEx.Execute(strPhrase)
intResultsCount = Matches.Count
If intResultsCount > 0 Then
matchPattern = intResultsCount
Else
matchPattern = "NO_MATCHES_FOUND"
End If
End Function
ON ERROR RESUME NEXT
Err.Clear
Dim objRegEx
Dim Matches
Dim intResultsCount
intResultsCount = 0
Set objRegEx = New RegExp
If (NOT IsObject(objRegEx)) Then
WScript.Echo "L_ERROR_CHECK_VBSCRIPT_VERSION"
End If
objRegEx.Global = True
objRegEx.IgnoreCase = True
objRegEx.Pattern = strMatchPattern
Set Matches = objRegEx.Execute(strPhrase)
intResultsCount = Matches.Count
If intResultsCount > 0 Then
matchPattern = intResultsCount
Else
matchPattern = "NO_MATCHES_FOUND"
End If
End Function
예제,. wscript.echo matchPattern("[0-9]{4}", "2008") 는 매칭이 되므로, 1을 반환하며 지정된 매칭이 되는 횟수를 출력 해줌.
또는,. COM 개체를 이용하는 경우에는,.
Set objCmdLib = CreateObject("Microsoft.CmdLib")
Set objCmdLib.ScriptingHost = WScript.Application
a = "[0-9]{4}"
b = "2008"
wscript.echo objCmdLib.matchPattern(a, b)
Set objCmdLib.ScriptingHost = WScript.Application
a = "[0-9]{4}"
b = "2008"
wscript.echo objCmdLib.matchPattern(a, b)
댓글 없음:
댓글 쓰기