查找正则表达式Word的最后一次出现 [英] Find Last Occurrence of Regex Word
本文介绍了查找正则表达式Word的最后一次出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何找到带有字边界的单词的最后一次出现?我为单词创建了一个 / \btotal\b /
的正则表达式。我如何使用search()查找此表达式的最后一次出现?在此先感谢您的帮助!
How can I find the last occurrence of a word with word boundaries? I created a regex expression of /\btotal\b/
for the word. How would I use search() to find the last occurrence of this expression? Thanks in advance for the help!
推荐答案
您可以使用负向前瞻来获得最后一场比赛:
You can use negative lookahead to get the last match:
/(\btotal\b)(?!.*\b\1\b)/
(?!。* \ 1)
是否为预测,以断言所捕获的组#1即总
单词在当前比赛之前不存在。
(?!.*\1)
is negative lookahead to assert that captured group #1 i.e. total
word is NOT present ahead of the present match.
这篇关于查找正则表达式Word的最后一次出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文