MyTetra Share
Делитесь знаниями!
How to escape regular expression special characters using javascript?
Время создания: 13.07.2018 15:30
Текстовые метки: javascript regexp escape special characters
Раздел: Javascript
Запись: Velonski/mytetra-database/master/base/1530775904iltlvi8ih7/text.html на

Use the \ character to escape a character that has special meaning inside a regular expression.

To automate it, you could use this:

function escapeRegExp(text) {

return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');


Update: There is now a proposal to standardize this method, possibly in ES2016:

Update: The abovementioned proposal was rejected, so keep implementing this yourself if you need it.

Так же в этом разделе:
MyTetra Share v.0.60
Яндекс индекс цитирования