In this HackerRank Day 7: Regular Expressions II 10 days of javascript problem solution 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 s 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 problem solution

Problem solution in JavaScript programming.

function regexVar() {
     * Declare a RegExp object variable named 're'
     * It must match a string that starts with 'Mr.', 'Mrs.', 'Ms.', 'Dr.', or 'Er.', 
     * followed by one or more letters.
    var re  = new RegExp(/^(Dr|Mr|Mrs|Ms|Er)\.[a-zA-Z]+$/g);
     * Do not remove the return statement
    return re;