valiamaximova1

js exam regex

Apr 3rd, 2021 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     // let regex = /(?<username>U\\$[A-Z][a-z][a-z]+U\\$)(?<password>P@\\$[a-z]{5,}[1-9]+P@\\$)/gm
  3.     // let regex1 = /U\$[A-Z][a-z][a-z]+U\$P@\$[a-z]{5,}[1-9]+P@\$/gm
  4.     // let regex2 = /U\$(?<username>[A-Z][a-z][a-z]+)U\$P@\$(?<password>[a-z]{5,}[1-9]+)P@\$/g;
  5.     //
  6.     // let number = Number(arr[0]);
  7.     // let count = 0;
  8.     //
  9.     // for (let i = 1; i <= number; i++) {
  10.     //     let input =  arr[i];
  11.     //     let match = regex2.exec(input);
  12.     //     if(match){
  13.     //         console.log('Registration was successful')
  14.     //         console.log(`Username: ${match.groups.username}, Password: ${match.groups.password}`)
  15.     //         count++
  16.     //     }else{
  17.     //         console.log('Invalid username or password')
  18.     //     }
  19.     // }
  20.  
  21.     input.shift();
  22.     let count = 0;
  23.     for (const line of input) {
  24.         let regex = /U\$(?<username>[A-Z][a-z][a-z]+)U\$P@\$(?<password>[a-z]{5,}[1-9]+)P@\$/g;
  25.         let match = regex.exec(line);
  26.         if(match){
  27.             console.log(`Registration was successful`);
  28.             console.log(`Username: ${match.groups.username}, Password: ${match.groups.password}`);
  29.             count++;
  30.         }else{
  31.             console.log(`Invalid username or password`);
  32.         }
  33.     }
  34.  
  35.     console.log(`Successful registrations: ${count}`)
  36. }
Add Comment
Please, Sign In to add comment