I want it to display "Dr. House" instead of Dr. Greg house and I am only allowed to modify "const re = /^(w+.s)(w+sw+)$/;". Can anyone help me?
here is the code
const userName = "Dr. Greg House"; // Code will also be tested with "Mr. Howard Wolowitz"
/* Your solution goes here */
const re = /^(w+.s)(w+sw+)$/;
const result = re.exec(userName);
console.log(result[1] + " " + result[2]);
2
Answers
Use capturing groups only for the words you need to keep:
A
.replace()
combined with a.trim()
will do the job just as well: