标签:
var input = "foobar"; var result = input.replace(‘bar‘, ‘$`‘); // $`: replace ‘bar‘ with everything before our match.--> foofoo var input = "foobarbaz"; var result = input.replace(‘bar‘, ‘$&‘); // $&: the match one --> foobarbaz var input = "foobarbaz"; var result = input.replace(‘bar‘, ‘$\‘‘); // $‘: replace with everything come after the match --> foobazbaz var input = "foobarbaz"; var result = input.replace(‘bar‘, ‘$$‘); // repalce with $ --> foo$baz var input = "foobarbaz"; var result = input.replace(‘bar‘, ‘?‘); // replace with ? --> foo?baz console.log(result);
[Javascript] Regex: '$`', '$&', '$''
标签:
原文地址:http://www.cnblogs.com/Answer1215/p/5132173.html