擅长:python、mysql、java
<p><code>re.sub</code>未正确使用。你知道吗</p>
<p>从<a href="https://docs.python.org/2/library/re.html#re.sub" rel="nofollow noreferrer">documentation for ^{<cd1>}</a>,您可以传递一个字符串或替换函数,在找到匹配项时返回字符串。你知道吗</p>
<blockquote>
<p><strong>Notice:</strong>
You can use any of the methods in answers to questions in the
duplicate flags to pad single digits.</p>
</blockquote>
<pre><code>def replace_ip(match):
last_octet = match.group(1)
return "".join((
'Host-Name',
last_octet.zfill(2)
))
re.sub(r'192.168.38.(\d+)', replace_ip, ips_from_file)
</code></pre>