擅长:python、mysql、java
<p>所有这些测试用例都由Python中的一个简单的重新表达式来处理。示例:</p>
<pre><code>>>> a = "the cooks."
>>> b = "cooks"
>>> c = " cook."
>>> d = "the cook is"
>>> e = "cook."
>>> tests = [a,b,c,d,e]
>>> for test in tests:
rc = re.match("[^c]*(cook)[^s]", test)
if rc:
print ' Found: "%s" in "%s"' % (rc.group(1), test)
else:
print ' Search word NOT found in "%s"' % test
Search word NOT found in "the cooks."
Search word NOT found in "cooks"
Found: "cook" in " cook."
Found: "cook" in "the cook is"
Found: "cook" in "cook."
>>>
</code></pre>