Echo JS 0.11.0

<~>

MaxArt 1738 days ago. link 2 points
I knew about $&, but TIL about $' and $`.
Thanks Stefan! (Although I'm not sure I'll ever use it 😅)
joncys 1737 days ago. link 0 point
These specific character sequences are part of regular expression substitution flags (correct me if I'm wrong on the terms), so you can also use capture group references, which are arguably more useful in most replace scenarios, such as:

// results in <div>hello</div>
'<div></div>'.replace(/(<div>)(<\/div>)/, '$1hello$2')

// or you can make it more explicit, because the function
// receives result of RegExp.exec(String)
'<div></div>'.replace(/(<div>)(<\/div>)/, (match, g1, g2) => `${g1}hello${g2}`)