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-"
您可能感兴趣的文章: