darkmavis1980

Untitled

Nov 30th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const regex = /([\d]{4})([\d]{2})([\d]{2})([\d]{2})([\d]{2})([\d]{2})/gm;
  2. const str = `20181008163451`;
  3. let m;
  4.  
  5. while ((m = regex.exec(str)) !== null) {
  6.     // This is necessary to avoid infinite loops with zero-width matches
  7.     if (m.index === regex.lastIndex) {
  8.         regex.lastIndex++;
  9.     }
  10.    
  11.     // The result can be accessed through the `m`-variable.
  12.     m.forEach((match, groupIndex) => {
  13.         console.log(`Found match, group ${groupIndex}: ${match}`);
  14.     });
  15. }
Add Comment
Please, Sign In to add comment