My Code:
I tried the following code
var str="I like green and want to build a GREENERY Earth with greening!";
var n=str.match(/green/g);
It is giving the result as
green,green
But I need the result as
green,GREEN,green
That is, I want to match both uppercase and lowercase letters. In this case, totally 3 green words are found.
My Code:
I tried the following code
var str="I like green and want to build a GREENERY Earth with greening!";
var n=str.match(/green/g);
It is giving the result as
green,green
But I need the result as
green,GREEN,green
That is, I want to match both uppercase and lowercase letters. In this case, totally 3 green words are found.
Share Improve this question edited Dec 6, 2012 at 7:50 Engineer 48.8k12 gold badges90 silver badges92 bronze badges asked Dec 6, 2012 at 7:39 EarthEarth 3,5716 gold badges42 silver badges84 bronze badges 1- try it var n=str.match(/green/ig); – ke20 Commented Dec 6, 2012 at 7:42
1 Answer
Reset to default 19Use i
flag, which will ignore the case-sensitiveness:
var n=str.match(/green/gi);
// ^----here it is
demo