正向前瞻不会在第一次出现时停止 [英] Positive lookahead doesn't stop at first occurrence
本文介绍了正向前瞻不会在第一次出现时停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用正则表达式
(?<=Charset:\s).+(?=
)
在下面的数据上(数据中没有换行符,我做的更好看)捕获Charset字符串
参数<div class="box_c">字符集:i763zLFYKBqVs@nZ8PyO}N9<br/>输入基数:23 溶液基数:19 ^时限:3.1416 秒
然而,我的比赛结束了
i763zLFYKBqVs@nZ8PyO}N9
输入基数:23溶液基数:19 <br/>时限:3.1416 秒
似乎在第一次出现后,正向前瞻并没有停止.有没有办法让它停止?
解决方案
一个简单的方法是使用非贪婪运算符.
(?<=Charset:\s).+?(?=
)
I use the regex
(?<=Charset:\s).+(?=<br\/>)
on the following data (There is no newline char in the data, I made it look better) to capture the Charset string
<div class="box_t">Parameters</div>
<div class="box_c">Charset: i763zLFYKBqVs@nZ8PyO}N9<br/>
Input Base: 23<br/>Solution Base: 19<br/>
Timelimit: 3.1416 seconds<br/></div>
However, my match ended up being
i763zLFYKBqVs@nZ8PyO}N9<br/>
Input Base: 23<br/>
Solution Base: 19<br/>
Timelimit: 3.1416 seconds
It seems that the positive lookahead did not stop after the first occurrence. Is there a way to make it stop?
解决方案
An easy way is to use the non-greedy operator.
(?<=Charset:\s).+?(?=<br\/>)
这篇关于正向前瞻不会在第一次出现时停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文