Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function extractWords(input) {
- const regex = /\b[A-Z]+\b/gm;
- const str = input;
- let m;
- let arr = [];
- 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) => {;
- arr.push(match);
- });
- }
- console.log(arr.join(', '));
- }
Advertisement
Add Comment
Please, Sign In to add comment