I
I
ince2020-06-14 22:18:49
JavaScript
ince, 2020-06-14 22:18:49

How to quote a regular expression?

How to quote a regular expression?
I find a substring in the text and I want to not just replace it with another using replace, but use the found expression as an argument and frame it in quotes.
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2020-06-14
@ince

const textConst = "Hello world";
const re = /(.l.)/g;
const newText  = textConst.replace(re, '**$1**');
console.log(newText)

https://developer.mozilla.org/en-US/docs/Web/JavaS...
5ee67d48ddae1436034822.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question