【发布时间】:2021-07-05 20:15:14
【问题描述】:
鉴于以下文字,我想将括号内的空格替换为“-”
str = 'these are the (1st 2nd and last) places'
// expected result
// 'these are the (1st-2nd-and-last) places'
换句话说,替换所有以'('和(something)开头,后跟(something)和')'的空格。
我开始了
/(?<=\(\w+)\s/g
但是(regex101 告诉我)“lookbehind 中的量词使其宽度不固定”(参考\w+)。有什么更好的方法来解决这个问题?
【问题讨论】:
标签: javascript regex