给定以下句子:Crazy Fredrick bought many very exquisite opal jewels.,什么正则表达式可以让我过滤掉其他所有单词?我正在这样替换我:

"Crazy Fredrick bought many very exquisite opal jewels.".replace(/regex goes here/gi, "replace string goes here")


因此,我想创建一个正则表达式将其转换为Fredrick many exquisite jewels.crazy bought very opal

最佳答案

可以使用以下内容(假设您的单词都用\ w匹配)

"Crazy Fredrick bought many very exquisite opal jewels.".replace(/(\w+) (\w+)/g, '$1');
-> "Crazy bought very opal."


用$ 2替换$ 1可得到:

"Fredrick many exquisite jewels."

07-23 05:05