Test if a Match Can Be Found Within a Subject String (测试匹配是否可以在字符串中找到)

前端之家收集整理的这篇文章主要介绍了Test if a Match Can Be Found Within a Subject String (测试匹配是否可以在字符串中找到)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

需求:

The regex pattern can be found中的regex pattern


方法

1. Python

a. Global function

import re

if re.search("regex pattern",subject):

print "Match Pass!"

else:

print "Match Fail!"


b. Compiled object

import re

reobj = re.compile("regex pattern")

if reobj.search(subject):

print "Match Pass!"

else:

print "Match Fail!"


2. Tcl

set result [regexp -linestop {regexp pattern} $subject]

if {$result == 1} {

puts "Match Pass!"

} else {

puts "Match Fail!"

}

猜你在找的正则表达式相关文章