NastySwipy

Software-Technologies - 08. Capital-Case Words

Jul 11th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function extractWords(input) {
  2.     const regex = /\b[A-Z]+\b/gm;
  3.     const str = input;
  4.     let m;
  5.     let arr = [];
  6.     while ((m = regex.exec(str)) !== null) {
  7.         // This is necessary to avoid infinite loops with zero-width matches
  8.         if (m.index === regex.lastIndex) {
  9.             regex.lastIndex++;
  10.         }
  11.  
  12.         // The result can be accessed through the `m`-variable.
  13.         m.forEach((match, groupIndex) => {;
  14.             arr.push(match);
  15.         });
  16.     }
  17.     console.log(arr.join(', '));
  18. }
Advertisement
Add Comment
Please, Sign In to add comment