JavaScript的String字符串对象常用操作总结(2)

var text = 'xxx-love-xxx'; var pattern = /xxx/g; var result = text.replace(pattern,'2') result// "2-love-2" text.replace(/(xxx)-\w{4}-(xxx)/g,'I love YOU');//"I love YOU" var text = 'xxx-love-xxx'; var pattern1 = /xxx/g; var result = text.replace(pattern1,'$$') result// "$-love-$" var result = text.replace(pattern1,'$&2') result//"xxx2-love-xxx2" var result = text.replace(pattern1,'$\'') result//"-love-xxx-love-"

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzpzxg.html