gpt4 book ai didi

javascript - 替换字符串中间的点

转载 作者:行者123 更新时间:2023-11-28 20:59:18 24 4
gpt4 key购买 nike

假设我们有一个数组(换行符分隔),例如:

hello
example.com
test.
something.
aspacefront
test
test.us

成为一个数组

hello
example(dot)com.
test.
something.
aspacefront
test
test(dot)us

这可以用正则表达式来完成吗?

我要循环数组,然后用这个正则表达式替换为 (dot) \b[^a-zA-Z\40]\b. 但它将是示例(dot )om 而不是 example(dot)com。

最佳答案

最简单的解决方案:

result = subject.replace(/\b\.\b/g, "(com)");

这意味着“仅替换前面和后面都有字母数字字符的点”。

关于javascript - 替换字符串中间的点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11427174/

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