MDN
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
Regular Expression
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes
基本的拉丁字母,包括下划线
\w === [A-Za-z0-9_]
\W === [^A-Za-z0-9_]
阿拉伯数字
\d === [0-9]
\D === [^0-9]
匹配单个空格字符,包括空格,制表符,换页符,换行符和其他Unicode空格。
\s === [ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]
\S === [^A-Za-z0-9_]
边界字符检测
// 前,后
\b
// 前,后
\B
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Assertions
分组
范围
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Groups_and_Ranges
量词
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Quantifiers
[^\w], [\W], [^A-Za-z]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes
group
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Groups_and_Ranges
const str = city.replace(/[^A-Za-z]/ig, ``).toLowerCase();
// const str = city.replace(/[\W]/ig, ``);
// const str = city.replace(/[^\w]/ig, ``);