📜  js reg 表达式选择大写 - Javascript 代码示例

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

代码示例1
const str = "HERE'S AN UPPERCASE PART of the string";
const upperCaseWords = str.match(/(\b[A-Z][A-Z]+|\b[A-Z]\b)/g);
// => [ 'HERE', 'S', 'AN', 'UPPERCASE', 'PART' ]
/*\b - start of the word
  [A-Z] - Any character between capital A and Z
  [A-Z]+ - Any character between capital A and Z, 
   but for one of more times and without interruption
  | - OR
  \b - start of the word
  [A-Z] - Any character between capital A and Z
  \b - end of the word
  g - global (run multiple times till string ends, 
      not just for one instance)*/