正则使用求教?

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

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

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

阅读 380
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)
})
推荐问题
宣传栏