Y
Y
Yurik7k2015-09-25 09:43:59
JavaScript
Yurik7k, 2015-09-25 09:43:59

How to find a word in a string case insensitive?

"Привет, мир".indexOf("Привет")returns 0, as it should
"Привет, мир".indexOf("привет")
return -1, as it should NOT, replaced "Hello" with "hello" the letter "p" became small
how to make the search case-insensitive?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Tolerant, 2015-09-25
@Yurik7k

If you do not need to search for the position where the value was encountered, you can use the regular expression:

var str = 'Привет, мир';
var reg = /привет/i;
reg.test(str) => true

V
Vitaly Volovich, 2015-09-25
@Fox_zp

use toLowerCase()
"Hello world".toLowerCase().indexOf("hello")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question