Advertisement
Guest User

Hide Data

a guest
Oct 5th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function hideData(array){
  2.     let nameRegex = /\*[A-Z][A-Za-z]+(?=\s|$)/g;
  3.     let phoneNumberRegex = /\+[0-9-]{10}(?=\s|$)/g;
  4.     let idRegex = /![a-zA-Z0-9]+(?=\s|$)/g;
  5.     let nameOfBaseRegex =/_[0-9A-Za-z]+(?=\s|$)/g;
  6.     let result = [];
  7.     for(let sentence of array){
  8.         let match =
  9.             sentence.match(nameRegex)
  10.             ||sentence.match(phoneNumberRegex)
  11.             ||sentence.match(idRegex)
  12.             ||sentence.match(nameOfBaseRegex) ;
  13.         while(match != null) {
  14.             for (let secret of match) {
  15.                 let hidden = '|'.repeat(secret.length);
  16.                 sentence = sentence.replace(secret,hidden);
  17.             }
  18.             match =
  19.                   sentence.match(nameRegex)
  20.                 ||sentence.match(phoneNumberRegex)
  21.                 ||sentence.match(idRegex)
  22.                 ||sentence.match(nameOfBaseRegex) ;
  23.         }
  24.         result.push(sentence);
  25.     }
  26.     console.log(result.join('\n'));
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement