Header Ad

HackerRank Day 7: Regular Expressions II 10 Days of javascript solution

In this HackerRank Day 7: Regular Expressions II 10 days of javascript problem you need to Complete the function in the editor below by returning a RegExp object, re, that matches any string s satisfying both of the following conditions:

  1. String  starts with the prefix Mr., Mrs., Ms., Dr., or Er.
  2. The remainder of string s (i.e., the rest of the string after the prefix) consists of one or more upper and/or lowercase English alphabetic letters (i.e., [a-z] and [A-Z]).

HackerRank Day 7: Regular Expressions II 10 Days of javascript solution


HackerRank Day 7: Regular Expressions 10 Days of javascript problem solution.


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});

function readLine() {
    return inputString[currentLine++];
}



function main() {
    const re = regexVar();
    const s = readLine();
    
    console.log(!!s.match(re));
}


Post a Comment

0 Comments