Advertisement
knoteva

Untitled

Sep 3rd, 2019
697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function password(input) {
  2.   let numberOfPasswords = input.shift();
  3.   let regexPass = /^(.+)>(\d{3})\|([a-z]{3})\|([A-Z]{3})\|([^<>]{3})<\1$/;
  4.   // регекс с именовани групи
  5.   //let regexPass = /^(.+)>(?<first>\d{3})\|(?<second>[a-z]{3})\|(?<third>[A-Z]{3})\|(?<fourth>[^<>]{3})<\1$/;
  6.  
  7.   for (let i = 0; i < numberOfPasswords; i ++) {
  8.     let matches = regexPass.exec(input[i]);
  9.     if(matches){
  10.       console.log(`Password: ${matches[2]}${matches[3]}${matches[4]}${matches[5]}`);
  11.       // С именовани групи
  12.       //console.log(`Password: ${matches.groups.first}${matches.groups.second}${matches.groups.third}${matches.groups.fourth}`);
  13.     } else {
  14.         console.log(`Try another password!`);
  15.     }
  16.   }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement