我尝试了几种最后一次出现的方法,但是它们没有用。以下是我的情况,
abc def = ghi
abc def ghi = jkl
abc def ghi=jkl mno
对于第一行,我的捕获目标是“ def”。对于第二行,我的捕获目标是“ ghi”,对于第三行,我的捕获目标是“ ghi”。目标可以口头表达为“等号之前单词的最后出现”。
Perl的正则表达式应如何显示?
你可以使用这种模式
(\w+)(?=\s*=)
( # Capturing Group (1)
\w # <ASCII letter, digit or underscore>
+ # (one or more)(greedy)
) # End of Capturing Group (1)
(?= # Look-Ahead
\s # <whitespace character>
* # (zero or more)(greedy)
= # "="
) # End of Look-Ahead
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句