Surname Match Example

by sylumer

HTML

<html>
<body>

<p>
The text being passed in is "Mr. John Smith lives here"
</p>

<h3>
Matched Surname is:
</h3>
<p id="name_match_demo" style="color:red;"></p>

<script>
  let strInitial = "Mr. John Smith lives here"; 
  let strName = strInitial.match(/([M][r-s]\.\s)(\w*\s)(\w*)/);
  document.getElementById("name_match_demo").innerHTML = strName[3];
</script>

</body>
</html>