David Borges
David Borges

Reputation: 105

Regex to Name.Surname

I'm trying to filter user login names but keeps getting garbage along. The user names and surnames starts with capital letters. I'm using grep GNU 2.10.

Like Albert.Ohara

[A-Z].*[.][a-zA-Z].*

Then the following chars are either space or other punctuation i.e. /; i think it's missing some code "except punctuation or space".

Getting Albert.Ohara/blahblah or Albert.Ohara blah

Upvotes: 2

Views: 361

Answers (1)

anubhava
anubhava

Reputation: 785551

You can use this regex to match First.Last:

\b[A-Z][a-zA-Z]*\.[A-Z][a-zA-Z]*\b

Use grep -E for extended regex support.

RegEx Breakup:

\b          # word boundary
[A-Z]       # match an uppercase letter
[a-zA-Z]*   # match 0 or more of letter
\.          # match a literal DOT
[A-Z]       # match an uppercase letter
[a-zA-Z]*   # match 0 or more of letter
\b          # word boundary

Upvotes: 3

Related Questions