$ grep -Px 'S\pL*\p{Ll}\pL*, (?!S)\p{Lu}\pL*\p{Ll}\pL*' < your-file
Smith, Paul
SbBBB, PaUU
Would report lines that start with S
followed by any number of letters (characters with L
etter p
roperty), followed by 1 lower case letter, followed by any number of letters followed by ", "
, and an uppercase letter other than S
and again a number of letters, at least one of which lower case.
PCRE \pL
, like POSIX [[:alpha:]]
is not limited to letters in alphabetic scripts; that includes word characters of any script. You could replace with [\p{Ll}\p{Lu}]
to only match on letters that can be considered either lower or upper case or with \p{Latin}
for any letter in the Latin script (as used in English, French, Spanish...) and (?=\p{Latin})\p{Ll}
for a lower case letter in the Latin script only (not those in Greek, Cyrillic, etc scripts) for instance.
To use those [a-z]
and only match on the 26 lowercase letters of the US ASCII charset, you'd need to fix the locale to C
/POSIX
and then you don't even need PCRE:
L='[A-Za-z]' Ll='[a-z]'
LC_ALL=C grep -x "S$L*$Ll$L*, [A-RT-Z]$L*$Ll$L*"
Note that it won't match on Serra, Éric
for instance as that É
is not matched by [A-RT-Z]
in the C locale.
SbBBB, PaUU
?[a-z]
matches a lot of characters (such as⒜
,⅍
) which I wouldn't consider "alphabetic". And there are a lot of characters that I would call alphabetic (such the Greek letters which gave their name to the alphabet word or the uppercase Latin letters) which it doesn't match.