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: '$`', '$&', '$''
时间: 2024-10-05 21:22:02