| 環境 | 分隔符 | 範例 |
|---|---|---|
| JavaScript / VBScript (RegExp 物件) | 字串常值 | "pattern" |
| Visual Basic Scripting Edition (舊版) | 正斜線 | /pattern/ |
現代 VBScript 統一使用 RegExp 物件,Pattern 屬性接收字串。
Dim re
Set re = New RegExp
re.Pattern = "expression" ' 核心模式字串
re.Global = True
re.IgnoreCase = True
re.MultiLine = False
正則模式由下列組件任意組合而成:
[abc][a-z]cat|dog* + ? {n,m}^ $ \b \B(...) (?:...) (?=...) (?!...)
Function IsValidEmail(email)
Dim re
Set re = New RegExp
re.Pattern = "^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$"
re.IgnoreCase = True
IsValidEmail = re.Test(email)
End Function
Execute 檢視 Match.SubMatches 調試群組捕獲Global 若只需首次匹配以提升效能