Advertisement
valchak

Secret Data

Feb 2nd, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function secretData(inputArr) {
  2.     let namesRegex = /(\*)([A-Z][a-zA-Z]*)(?=\s|$|\.)/g;
  3.     let phoneRegex = /(\+)([0-9-]{10})(?=\s|$|\.)/g;
  4.     let idRegex = /(!)([a-zA-Z0-9]+)(?=\s|$|\.)/g;
  5.     let secretBaseRegex = /(_)([a-zA-Z0-9]+)(?=\s|$|\.)/g;
  6.  
  7.     let resultStr = inputArr.join('\n');
  8.     resultStr = resultStr.replace(namesRegex, replaceFunc);
  9.     resultStr = resultStr.replace(phoneRegex, replaceFunc);
  10.     resultStr = resultStr.replace(idRegex, replaceFunc);
  11.     resultStr = resultStr.replace(secretBaseRegex, replaceFunc);
  12.     console.log(resultStr);
  13.  
  14.     function replaceFunc(fullMatch, p1) {
  15.         return '|'.repeat(fullMatch.length);
  16.     }
  17. }
  18. secretData(['Agent *Ivankov was in the room when it all happened.',
  19.     'The person in the room was heavily armed.',
  20.     'Agent *Ivankov had to act quick in order.',
  21.     'He picked up his phone and called some unknown number. ',
  22.     'I think it was +555-49-796',
  23.     'I can\'t really remember...',
  24.     'He said something about "finishing work" with subject !2491a23BVB34Q and returning to Base _Aurora21',
  25.     'Then after that he disappeared from my sight.',
  26.     'As if he vanished in the shadows.',
  27.     'A moment, shorter than a second, later, I saw the person flying off the top floor.',
  28.     'I really don\'t know what happened there.',
  29.     'This is all I saw, that night.']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement