You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VBScript.RegEx正则:为双字母匹配组添加PT大小写例外

正则表达式修改方案(适配VBScript.RegEx)

原捕获子组为:

([a-zA-Z]{2}|[a-zA-Z]{1}\d{1}|\d{1}[a-zA-Z]{1})

需要为第一个分支[a-zA-Z]{2}添加例外规则,排除任意大小写形式的"PT",修改后的正则表达式如下:

((?!PT)[a-zA-Z]{2}|[a-zA-Z]\d|\d[a-zA-Z])

关键说明

  • 使用负向先行断言(?!PT)排除"PT"组合,结合VBScript.RegEx的IgnoreCase=True配置,可覆盖所有大小写变体(PT/pt/pT等)。
  • 简化了原正则中的{1}量词(省略后不影响匹配逻辑)。

匹配验证(对应需求表格)

单词结果
AAPass
A1Pass
1APass
PTFail
ptFail
pTFail

VBScript示例代码

Dim regEx, match, testWords
Set regEx = New RegExp
regEx.Pattern = "((?!PT)[a-zA-Z]{2}|[a-zA-Z]\d|\d[a-zA-Z])"
regEx.IgnoreCase = True ' 启用不区分大小写匹配
regEx.Global = False

' 测试用例数组
testWords = Array("AA", "A1", "1A", "PT", "pt", "pT")

For Each word In testWords
    Set match = regEx.Execute(word)
    If match.Count > 0 Then
        WScript.Echo word & " -> Pass"
    Else
        WScript.Echo word & " -> Fail"
    End If
Next

内容的提问来源于stack exchange,提问作者rndldvl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 03:52:56