Echo JS 0.11.0

<~>
joncys 1751 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}`)

Replies