admin管理员组文章数量:1336077
I have a string like
{{token1}}/{{token2}}
I want to match {{token2}}
using regex.
other possible cases that it should match are
{{token1}}/{
should match {
(the last one).
{{token1}}/{{
should match {{
(the last one).
{{token1}}/{{token2
should match {{token2
.
I tried /\S+$/
but it works when the string is {{token1}} {{token2}}
.
Thanks in advance.
I have a string like
{{token1}}/{{token2}}
I want to match {{token2}}
using regex.
other possible cases that it should match are
{{token1}}/{
should match {
(the last one).
{{token1}}/{{
should match {{
(the last one).
{{token1}}/{{token2
should match {{token2
.
I tried /\S+$/
but it works when the string is {{token1}} {{token2}}
.
Thanks in advance.
Share Improve this question edited Dec 2, 2016 at 6:55 Prashant Agrawal asked Dec 2, 2016 at 6:43 Prashant AgrawalPrashant Agrawal 67010 silver badges25 bronze badges 4- Can you explain what you mean by "match"?. Do you want to "extract it"? – TheLostMind Commented Dec 2, 2016 at 6:48
- @Tushar I have update the question with all possible scenarios – Prashant Agrawal Commented Dec 2, 2016 at 6:56
- @TheLostMind I am searching this pattern in a string. – Prashant Agrawal Commented Dec 2, 2016 at 6:57
- Does this answer your question? Find Last Occurrence of Regex Word – pilchard Commented Oct 2, 2021 at 12:12
1 Answer
Reset to default 6You can use a negative lookahead regex:
/{+[^}]*}*(?!.*{)/
(?!.*{)
is negative lookahead that asserts we don't have any {
ahead of the current position.
RegEx Demo
本文标签: javascriptHow to match the last occurrence of a pattern using regexStack Overflow
版权声明:本文标题:javascript - How to match the last occurrence of a pattern using regex - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742378879a2463715.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论