gpt4 book ai didi

javascript正则表达式将所有重复的选项卡新行替换为单个新行

转载 作者:行者123 更新时间:2023-12-03 03:08:25 25 4
gpt4 key购买 nike

尝试使用 javascript 正则表达式将所有重复的选项卡新行替换为单个新行。使用一些在线测试仪显示它可以工作。但它不是在 JavaScript 中。有人可以帮忙

var str;
str.replace(/[\t \n,]+/, ",");

input: UIPLAT-234 UIPLAT-342,UIPLAT-3452<\t>UIPLAT-23<\n>UIPLAT-55
the above <\t> and <\n> represent the input of a tab and new line

最佳答案

您需要添加全局标志:

str.replace(/[\t \n,]+/g, ",");

关于javascript正则表达式将所有重复的选项卡新行替换为单个新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47059346/

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