我有一个字符串如下:
var email = "name(replace these parenthesis by @)domain.com"
如何(replace these parenthesis by @)
使用 javascript 用 @ 替换部分?
我有一个字符串如下:
var email = "name(replace these parenthesis by @)domain.com"
如何(replace these parenthesis by @)
使用 javascript 用 @ 替换部分?
email.replace("(replace these parenthesis by @)", "@")
如果您确定该模式,则可以使用正则表达式。(和@)之间的每个字符都将替换为@
var str = "name(replace these parenthesis by @)domain.com";
var patt1 = /\(.*@\)/i;
document.write(str.replace(patt1,"@"));
对于您呈现的字符串格式:
var email = "name(replace these parenthesis by @)domain.com";
这样做:
email.replace(/\(.*\)/g,"@");
会给
name@domain.com
如果内容与您提到的一样,(replace these paranthesis by @)
您可以将其替换为:
var email = "name(replace these parenthesis by @)domain.com";
email.replace(/(replace these parenthesis by @)/g,"@");
还是您正在寻找更通用的东西?