擅长:python、mysql、java
<p>这项工作:</p>
<pre><code>import re
txt='''\
text num
test one 3.5 and 60 test tow 3.5/60
test one 3/4 test tow 3/4
test one 5.0 test tow 5.0'''
for line in txt.splitlines():
m=re.search(r'^(.*?[ \t]{2,}(?=\d))([0-9.\/]+)$', line)
if m:
a,_,b=m.group(2).partition('/')
if re.search(fr'\b{m.group(2)}\b', m.group(1)):
l=len(m.group(1))
s=re.sub(fr'[ ]?\b{m.group(2)}\b', '', m.group(1))
line=s+' '*(l-len(s))+m.group(2)
elif re.search(fr'{a}[^/]+{b}', m.group(1)):
l=len(m.group(1))
s=re.sub(fr'[ ]?\b{a}\b','',m.group(1))
s=re.sub(fr'[ ]?\b{b}\b','',s)
line=s+' '*(l-len(s))+m.group(2)
print(line)
</code></pre>
<p>印刷品:</p>
<pre><code>text num
test one and test tow 3.5/60
test one test tow 3/4
test one test tow 5.0
</code></pre>