擅长:python、mysql、java
<p><strong>正则表达式是您想要的。你知道吗</p>
<p>由于要检查字符串中的模式,因此可以通过<code>re</code>库利用python对正则表达式的内置支持。你知道吗</p>
<p>示例:</p>
<pre><code>#To check if there is a period internal to a sequence of letters with no adjacent whitespace
import re
str = 'www.google.com'
pattern = '.*\..*'
obj = re.compile(pattern)
if obj.search(str):
print "Pattern matched"
</code></pre>
<p>类似地,为要签入字符串的条件生成模式。你知道吗</p>
<pre><code>#If there is a period and it is followed by a whitespace followed by a lowercase letter
regex = '.*\. [a-z].*'
</code></pre>
<p>您可以使用<a href="https://regex101.com" rel="nofollow noreferrer">this</a>简单工具在线生成和测试正则表达式</p>
<p>更广泛地阅读<code>re</code>库<a href="https://docs.python.org/2/library/re.html" rel="nofollow noreferrer">here</a></p>