RegEx Help - Middle Names

Hi All,

I am struggling with creating a regex to recognize all three situations (I currently can recognize 2 of 3)

Greg, John T
Greg, John T.
Greg, John Timothy

As you can see, all three options (middle initial, middle initial with period, full middle initial) must be recognized by the expression.



Is this the desired behaviour?

Almost – I need to capture the period after the middle initial – some documents contain “Greg, Joseph T.” and the regex won’t find it without the period.


This should work then: \w+,\s\w+\s\w+.{0,1}


Try this pattern \w+,?\s*\w+\s*\w+\.?

@alin.ferenczi small change to the pattern instead of .{0,1} use \.? . Because . dot literally matches everything except for new line. For instance it will match Greg, John T$ too.

1 Like