当使用数字和字符串作为模式时,tcl 中的正则表达式与我的模式不匹配

问题描述 投票:0回答:0

我有一个正在使用的正则表达式,我正在尝试匹配 python 中的表达式,但我是 tcl 的新手,似乎无法让正则表达式工作。

set string"abc08_batman"
set patternOne "abc.*Batman"
set patternTwo "abc\d+.*Batman"
set patternThree "abc\d{2}.*Batman"

if {[regexp -nocase $pattern $string c]} {
   puts "Full Match 2: $c"
}

patternOne
有效但不够好,
patternTwo
是我喜欢的但它们不起作用。

以下有效,但我不能硬编码

08
,因为这违背了使用正则表达式的目的。我现在被锁定到
abc08

if {[regexp -nocase "abc08.*batman" $string c]} {
    puts "Full Match: $c"
} 
regex tcl
© www.soinside.com 2019 - 2024. All rights reserved.