📌  相关文章
📜  js 字符串包含子字符串忽略大小写 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:31.241000             🧑  作者: Mango

代码示例1
const str = 'arya stark';

// The most concise way to check substrings ignoring case is using
// `String#match()` and a case-insensitive regular expression (the 'i')
str.match(/Stark/i); // true
str.match(/Snow/i); // false

// You can also convert both the string and the search string to lower case.
str.toLowerCase().includes('Stark'.toLowerCase()); // true
str.toLowerCase().indexOf('Stark'.toLowerCase()) !== -1; // true

str.toLowerCase().includes('Snow'.toLowerCase()); // false
str.toLowerCase().indexOf('Snow'.toLowerCase()) !== -1; // false