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