这是非常接近的桑托斯·辛格回答,但不会取代之间的空间is和5。
const regex = /(\d)\s+(?=\d)/g;
const str = `The store is 5 6 7 8`;
const subst = `$1`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);Run Code Online (Sandbox Code Playgroud)
https://regex101.com/r/nSZfQR/3/
你好你可以试试这个。
var str = "The store is 5 6 7 8"
var regex = /(\d+)/g;
str.split(/[0-9]+/).join("") + str.match(regex).join('')
Run Code Online (Sandbox Code Playgroud)
希望这会起作用。
| 归档时间: |
|
| 查看次数: |
2189 次 |
| 最近记录: |