本节内容:
python任意字符匹配
1. 需求
1.1 匹配任意非(line break)字符
1.1.1. Tcl
a. Reg
.
b. Code
复制代码 代码示例:
if [regexp -linestop {.} $subject] {
# Successful match
} else {
# Match attempt failed
}
1.1.2 Python
a. Reg
.
b. Code
复制代码 代码示例:
if re.search(".", subject):
# Successful match
else:
# Match attempt failed
1.2 匹配任意字符 (包含line speak)
1.2.1. Tcl
a. Reg
(?s).
b.Code
复制代码 代码示例:
if [regexp -linestop {(?s).} $subject] {
# Successful match
} else {
# Match attempt failed
}
or
if [regexp {.} $subject] {
# Successful match
} else {
# Match attempt failed
}
1.1.2 Python
a. Reg
(?s).
b. Code
复制代码 代码示例:
if re.search("(?s).", subject):
# Successful match
else:
# Match attempt failed
or
if re.search(".", subject, re.DOTALL):
# Successful match
else:
# Match attempt failed