regex 删除字符串的某一部分

rdrgkggo  于 2023-06-25  发布在  其他
关注(0)|答案(1)|浏览(83)

我有一个如下格式的字符串:

No Status: not enough information to provide one. more research and data-gathering is required.

我试图删除':'之后的所有内容,直到'.'之后的第一个空格,这样结果将如下所示:

No Status: more research and data-gathering is required.

有没有什么正则表达式可以在JavaScript中实现这一点?

jm2pwxwz

jm2pwxwz1#

简单的字符串替换不需要正则表达式:

let myString = 'No Status: not enough information to provide one. more research and data-gathering is required.';

let newString = myString.replace('not enough information to provide one. ', '');

console.log(newString);
  • 或 * with regex:
let myString = 'No Status: not enough information to provide one. more research and data-gathering is required.';

let newString = myString.replace(/:.*?\./, ':');

console.log(newString);

相关问题