I have the following string, and I want to match the contents of the last curly brace (inclusive), ie the output should be {ahhh}
.
abc {popo}/popo/{ahhh}
Golang does not support negative lookahead, and I have tried the following patterns but it has not worked
{.+?}$
{.+?}([^/])
Any help would be much appreciated. Thank you.
You could match from an opening till closing curly at the end of the string:
\{[^{}]*}$
Or you could match the whole line, and then capture the last occurrence of the curly's followed by matching any char except /
till the end of the string.
.*(\{[^{}]*})[^/]*$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.