I found this exercise on CodeWars on how to abbreviate a string and insert a dot in the initials.
While looking for a solution I came across that there is a match () method with the following regular expressions (
I absolutely didn’t know how to solve it and the only solutions that came to mind was to scroll through the string and take the first value as an index, but I didn’t know how to take the index of the initial of the last name)
var user = "Sam Harris" var matches = user.match(/\b(\w)/g); // this var abbrevation = matches.join("."); // this console.log(abbrevation);
I asked first if my reasoning without looking at the solution on the Internet was fine and how does that regular expression translate?