gpt4 book ai didi

javascript - 正则表达式查找大括号内的字符串Javascript

转载 作者:行者123 更新时间:2023-11-28 19:12:42 24 4
gpt4 key购买 nike

我正在尝试使用正则表达式获取大括号内的子字符串。

假设我有以下字符串:

"This is a {nice} text to search for a {cool} substring".

我希望能够搜索nicecool

最佳答案

尝试如下:

var myString = "This is a {nice} text to search for a {cool} substring",
pattern = /[^{}]*(?=\})/g;

console.log(myString.match(pattern));

关于javascript - 正则表达式查找大括号内的字符串Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30483613/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com