Skip to content

Latest commit

 

History

History
159 lines (84 loc) · 3.37 KB

README.md

File metadata and controls

159 lines (84 loc) · 3.37 KB

Regular Expressions All In One

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

Regular Expressions & Cheatsheet

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#Character_classes

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes

\w & \W

基本的拉丁字母,包括下划线

\w === [A-Za-z0-9_]

\W === [^A-Za-z0-9_]

\d & \D

阿拉伯数字

\d === [0-9]

\D === [^0-9]

\s & \S

匹配单个空格字符,包括空格,制表符,换页符,换行符和其他Unicode空格。

\s === [ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]

\S === [^A-Za-z0-9_]

\b & \B

边界字符检测

// 前,后
\b 

// 前,后
\B 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#Assertions

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Assertions

Group

分组

Range

范围

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#Groups_and_ranges

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Groups_and_Ranges

Quantifiers

量词

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#Quantifiers

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Quantifiers

refs

https://regexper.com/

Regular_Expressions

[^\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, ``);