JavaScript replaceAll case-insensitive search using variable rather than a string
问题 I want to do a JavaScript replaceAll() using a variable (rather than a string) in a case-insensitive search, but also retaining the case of the matched text (in the return). For example, console.log('doc.p:', doc.p.toString().substring(0, 26)) var query = this.manager.store.get('q').value.toString(); console.log('query:', query, '| type:', typeof(query)) console.log(doc.p.toString().replaceAll(/(dna)/gi, '***$1***')) console.log(doc.p.toString().replaceAll(/(query)/gi, '***$1***')) is giving