擅长:python、mysql、java
<p>你可以试试这个</p>
<p>代码:</p>
<pre><code>import re
regex = r"-?\d+"
test_str = "'alabama_bal_188321000_2000_name_variable_nmr_sw.csv'"
matches = re.finditer(regex, test_str)
for matchNum, match in enumerate(matches):
matchNum = matchNum + 1
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
</code></pre>
<p>结果:</p>
<pre><code>Match 1 was found at 13-22: 188321000
Match 2 was found at 23-27: 2000
</code></pre>