Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /
- ([\d]{4})([\d]{2})([\d]{2})([\d]{2})([\d]{2})([\d]{2})
- /
- gm
- 1st Capturing Group ([\d]{4})
- Match a single character present in the list below [\d]{4}
- {4} Quantifier — Matches exactly 4 times
- \d matches a digit (equal to [0-9])
- 2nd Capturing Group ([\d]{2})
- Match a single character present in the list below [\d]{2}
- {2} Quantifier — Matches exactly 2 times
- \d matches a digit (equal to [0-9])
- 3rd Capturing Group ([\d]{2})
- Match a single character present in the list below [\d]{2}
- {2} Quantifier — Matches exactly 2 times
- \d matches a digit (equal to [0-9])
- 4th Capturing Group ([\d]{2})
- Match a single character present in the list below [\d]{2}
- {2} Quantifier — Matches exactly 2 times
- \d matches a digit (equal to [0-9])
- 5th Capturing Group ([\d]{2})
- Match a single character present in the list below [\d]{2}
- {2} Quantifier — Matches exactly 2 times
- \d matches a digit (equal to [0-9])
- 6th Capturing Group ([\d]{2})
- Match a single character present in the list below [\d]{2}
- {2} Quantifier — Matches exactly 2 times
- \d matches a digit (equal to [0-9])
- Global pattern flags
- g modifier: global. All matches (don't return after first match)
- m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
- Match 1
- Full match 0-14 `20181008163451`
- Group 1. n/a `2018`
- Group 2. n/a `10`
- Group 3. n/a `08`
- Group 4. n/a `16`
- Group 5. n/a `34`
- Group 6. n/a `51`
- number
- ([\d]{4})([\d]{2})([\d]{2})([\d]{2})([\d]{2})([\d]{2})
- ([\d]{4})([\d]{2})([\d]{2})([\d]{2})([\d]{2})([\d]{2})
- 20181008163451
- const regex = /([\d]{4})([\d]{2})([\d]{2})([\d]{2})([\d]{2})([\d]{2})/gm;
- const str = `20181008163451`;
- let m;
- while ((m = regex.exec(str)) !== null) {
- // This is necessary to avoid infinite loops with zero-width matches
- if (m.index === regex.lastIndex) {
- regex.lastIndex++;
- }
- // The result can be accessed through the `m`-variable.
- m.forEach((match, groupIndex) => {
- console.log(`Found match, group ${groupIndex}: ${match}`);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement