Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的代码:
我尝试了以下代码
var str="I like green and want to build a GREENERY Earth with greening!"; var n=str.match(/green/g);
它给出的结果为
green,green
但我需要结果为
green,GREEN,green
也就是说,我想同时匹配大写和小写字母。在这种情况下,总共找到 3 个绿色单词。
使用i标志,它将忽略区分大小写:
i
var n=str.match(/green/gi); // ^----here it is
演示