I
I
Igor Bezlepkin2018-06-06 10:18:46
JavaScript
Igor Bezlepkin, 2018-06-06 10:18:46

How to find and replace a string without case sensitivity?

I know how to search. But here's how to replace the original no

function replace (str) {
  var mask = 'сан'
  return str.replace(new RegExp(mask, 'gi'), '<strong> + mask +</strong>')
}

replace('Санкт-Петербург');

// <strong>сан</strong>кт-петербург
// а нужно // <strong>Cан</strong>кт-петербург

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-06-06
@Bezlepkin

str.replace(RegExp(mask, 'gi'), '<strong>$&</strong>')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question