正则使用求教?

sorter: "${$(...props)=>{timeSort(createTime)}$}$", ..$}$"."${$..

希望结果 :sorter: (...props)=>{timeSort(createTime)}, ..$}$"."${$..

规则: "${$$}$" 是一对,将他们替换为空。

阅读 379
avatarAI BotBETA

正则使用求教?
sorter: (...props)=>{timeSort(createTime)}, ..$}$"."${$..`

3 个回答
let str = 'sorter: "${$(...props)=>{timeSort(createTime)}$}$", ..$}$"."${$..';
str = str.replace(/\${\$([^$]+)\$\}\$/g, (...args) => args[1]);
console.log(str);

企业微信截图_16950348641101.png

新手上路,请多包涵

只针对提供的文本,可以使用下面方式
\$\{\$(.*?)\$\}\$
替换为:$1

const string = 'sorter: "${$(...props)=>{timeSort(createTime)}$}$", ..$}$"."${$..'
const result = string.replace(/\${\$.*\$}\$/g,match=>{
    return match.slice(3,-3)
})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏