擅长:python、mysql、java
<p>可以使用string对象的rfind函数。在</p>
<pre><code>>>> lhost = "192.168.1.23"
>>> lhost[:lhost.rfind(".")] + ".0-255"
'192.168.1.0-255'
</code></pre>
<p>rfind函数与find()类似,但从末尾搜索。在</p>
<blockquote>
<p>rfind(...)
S.rfind(sub [,start [,end]]) -> int
Return the highest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure.</p>
</blockquote>
<p>更复杂的解决方案可以使用regular express:</p>
^{pr2}$
<p>希望对你有帮助!在</p>