Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I'm trying to get a string which matches by a regex pattern ( {$ ... } ). But I don't want the brackets and the $ sign returned.
For example
{$Testpath}/Testlink
should return
Testpath
My regex pattern looks like this at the moment:
^{\$.*}$
尝试以下正则表达式:
^\{\$\K[^}]*(?=\})
正则表达式 101 演示
这个表达式先是字符串的开头,^然后是文字{,然后是文字,$然后它会忽略那些使用\K锚点的内容,然后匹配一个或多个不是 a 的字符,}然后它会向前(?=\})查找文字}。
^
{
$
\K
}
(?=\})
您可能不需要行尾锚$,因为您尝试匹配的文本可能不会在字符串的末尾结束,并且您可能不需要行首^锚,因为相反的原因,这就是您的模式正在尝试匹配的可能不在字符串或行的开头。
我认为您应该删除^并$使用全局修饰符。