Test Whether a Regex Matches the Subject String Entirely (测试正则匹配是否完全匹配字符串)

前端之家收集整理的这篇文章主要介绍了Test Whether a Regex Matches the Subject String Entirely (测试正则匹配是否完全匹配字符串)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

需求:

字符串中只有regex pattern


方法

1. Python

a. Global function

import re

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

print "Match Pass!"

else:

print "Match Fail!"


b. Compiled object

import re

reobj = re.compile("regex pattern\Z")

if reobj.search(subject):

print "Match Pass!"

else:

print "Match Fail!"


2. Tcl

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

if {$result == 1} {

puts "Match Pass!"

} else {

puts "Match Fail!"

}

原文链接:https://www.f2er.com/regex/361757.html

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