擅长:python、mysql、java
<p>使用<code>re</code>(regex)查找模式,使用<code>input</code>输入文本:</p>
<pre><code>import re
a=input('Enter your stuff: ')
s=re.sub('[a-zA-Z^]','',a)
print([int('-'+i[0]) if s[s.index(i)-2]=='-' else int(i[0]) for i in re.split(' [+|-] ',s)])
</code></pre>
<p>输出示例:</p>
<pre><code>Enter your stuff: 2x^3 + 5x^2 - 8x + 3
[2, 5, -8, 3]
</code></pre>