-1

我有一个字符串如下:

var email = "name(replace these parenthesis by @)domain.com"

如何(replace these parenthesis by @)使用 javascript 用 @ 替换部分?

4

4 回答 4

4
email.replace("(replace these parenthesis by @)", "@")
于 2013-10-20T18:12:44.703 回答
2

如果您确定该模式,则可以使用正则表达式。(@)之间的每个字符都将替换为@

var str = "name(replace these parenthesis by @)domain.com";
var patt1 = /\(.*@\)/i;
document.write(str.replace(patt1,"@"));
于 2013-10-20T18:19:28.200 回答
1

对于您呈现的字符串格式:

var email = "name(replace these parenthesis by @)domain.com";

这样做:

email.replace(/\(.*\)/g,"@");

会给

name@domain.com
于 2013-10-20T18:22:54.977 回答
0

如果内容与您提到的一样,(replace these paranthesis by @)您可以将其替换为:

var email = "name(replace these parenthesis by @)domain.com";
email.replace(/(replace these parenthesis by @)/g,"@");

还是您正在寻找更通用的东西?

于 2013-10-20T18:14:58.433 回答