擅长:python、mysql、java
<p>尝试使用此模式:</p>
<pre><code>([^_]+)_(.*)_.*
</code></pre>
<p>示例脚本:</p>
<pre><code>input = "ARSrt_FAC_RED5_DSR_AU16"
matches = re.match(r'([^_]+)_(.*)_.*', input)
if matchObj:
print "part1: ", matches.group(1)
print "part2: ", matches.group(2)
part1: ARSrt
part2: FAC_RED5_DSR
</code></pre>
<p>下面是regex模式的简要说明:</p>
<pre><code>([^_]+) match and capture the term before the first underscore
_ match a literal underscore
(.*) then greedily match and consume everything up until the last undescore
_ match the last underscore
.* consume the remainder of the string
</code></pre>