Advertisement
darkmavis1980

Untitled

Nov 30th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /
  3. ([\d]{4})([\d]{2})([\d]{2})([\d]{2})([\d]{2})([\d]{2})
  4. /
  5. gm
  6. 1st Capturing Group ([\d]{4})
  7. Match a single character present in the list below [\d]{4}
  8. {4} Quantifier — Matches exactly 4 times
  9. \d matches a digit (equal to [0-9])
  10. 2nd Capturing Group ([\d]{2})
  11. Match a single character present in the list below [\d]{2}
  12. {2} Quantifier — Matches exactly 2 times
  13. \d matches a digit (equal to [0-9])
  14. 3rd Capturing Group ([\d]{2})
  15. Match a single character present in the list below [\d]{2}
  16. {2} Quantifier — Matches exactly 2 times
  17. \d matches a digit (equal to [0-9])
  18. 4th Capturing Group ([\d]{2})
  19. Match a single character present in the list below [\d]{2}
  20. {2} Quantifier — Matches exactly 2 times
  21. \d matches a digit (equal to [0-9])
  22. 5th Capturing Group ([\d]{2})
  23. Match a single character present in the list below [\d]{2}
  24. {2} Quantifier — Matches exactly 2 times
  25. \d matches a digit (equal to [0-9])
  26. 6th Capturing Group ([\d]{2})
  27. Match a single character present in the list below [\d]{2}
  28. {2} Quantifier — Matches exactly 2 times
  29. \d matches a digit (equal to [0-9])
  30. Global pattern flags
  31. g modifier: global. All matches (don't return after first match)
  32. m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
  33. Match 1
  34. Full match  0-14    `20181008163451`
  35. Group 1.    n/a `2018`
  36. Group 2.    n/a `10`
  37. Group 3.    n/a `08`
  38. Group 4.    n/a `16`
  39. Group 5.    n/a `34`
  40. Group 6.    n/a `51`
  41.  
  42. number
  43.  
  44. ([\d]{4})([\d]{2})([\d]{2})([\d]{2})([\d]{2})([\d]{2})
  45. ([\d]{4})([\d]{2})([\d]{2})([\d]{2})([\d]{2})([\d]{2})
  46.  
  47. 20181008163451
  48. const regex = /([\d]{4})([\d]{2})([\d]{2})([\d]{2})([\d]{2})([\d]{2})/gm;
  49. const str = `20181008163451`;
  50. let m;
  51.  
  52. while ((m = regex.exec(str)) !== null) {
  53.    // This is necessary to avoid infinite loops with zero-width matches
  54.    if (m.index === regex.lastIndex) {
  55.        regex.lastIndex++;
  56.    }
  57.    
  58.    // The result can be accessed through the `m`-variable.
  59.    m.forEach((match, groupIndex) => {
  60.        console.log(`Found match, group ${groupIndex}: ${match}`);
  61.    });
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement