擅长:python、mysql、java
<p>要满足要求,可以使用以下正则表达式:</p>
<pre><code>def nthNumber_asked(s, n):
pattern = "\D*(?:\d+\D+){" + str(n-1) + "}0*(\d+)"
return re.match(pattern, s).group(1)
</code></pre>
<p>首先我寻找一个非数字,然后是n-1组数字+非数字(非捕获),最后我忽略所有的零,然后捕捉剩余的数字。但是,如果有一个只有零的数字,那么忽略所有的零是一个坏主意,因为它将被忽略。我更愿意在数字中加上0。否则,可能需要一个更复杂的具有前瞻性的模式。在</p>