gpt4 book ai didi

javascript - 删除标点符号前的空格javascript/jquery

转载 作者:行者123 更新时间:2023-11-29 16:14:04 27 4
gpt4 key购买 nike

我想删除 Javascript/jquery 中每个标点符号前的空格。例如

Input string = " This 's a test string ."

Output = "This's a test string."

最佳答案

"This string has some -- perhaps too much -- punctuation that 's not properly "
+ "spaced ; what can I do to remove the excess spaces before it ?"
.replace(/\s+(\W)/g, "$1");

//=> "This string has some-- perhaps too much-- punctuation that's not properly "
// + "spaced; what can I do to remove the excess spaces before it?"

关于javascript - 删除标点符号前的空格javascript/jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20047387/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com