jasonpriem/HumanNameParser.php

Regex patterns for Suffix and Title need updating

Opened this issue · 0 comments

This is good little parser, but trying it with php 7 I found that the Title and Suffix expressions no longer work as expected. The space between them and the name was not being detected in the pattern so names like "Frank Tester" were becoming "ank Tester"

Here's the update to those patterns. I will try to come back later and do a proper pull request, but for now, here's the update needed in Parse.php

         $nicknamesRegex
             = "/ ('|\"|\(\"*'*)(.+?)('|\"|\"*'*\)) /"; // names that starts or end w/ an apostrophe break this
 
-        $titleRegex = "/^($titles)/";
-        $suffixRegex = "/,* *($suffixes)$/";
+        $titleRegex = "/^($titles)\s+/";
+        $suffixRegex = "/\,?\s+($suffixes)$/";
         $lastRegex = "/(?!^)\b([^ ]+ y |$prefixes)*[^ ]+$/";
         $leadingInitRegex = "/^(.\.*)(?= \p{L}{2})/"; // note the lookahead, which isn't returned or replaced
         $firstRegex = "/^[^ ]+/"; //