Regex - words starting with capital letter and end with capital letter

Hi , I want to find words that start with capital letter and end with capital letter, tried this:

\\b([A-Z])+([a-zA-Z]+)?([A-Z])\\b

but it doesn"t work in here:

structure(list(Name_1 = c("Name_2", "Andy", "Angelica P.", "Angelica", 
"Andy A.", "Aaron", "Aaron J.", "Betty", "Barack O.", "Ben", 
"BettyX", "Barack", "Ben T.", "Chrissy", "Celeste J.", "Celeste", 
"Chrissy L.", "Cameron", "Cameron W.", "Candace", "Candace O.", 
"Danny", "Danny S.")), spec = structure(list(cols = list(Name_1 = structure(list(), class = c("collector_character", 
"collector"))), default = structure(list(), class = c("collector_guess", 
"collector")), delim = ","), class = "col_spec"), row.names = c(NA, 
-23L), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"
))

It should match only BettyX not others.
Any ideas will be greatly appreciated, thank you

How about this?

"^[A-Z][a-z]*[A-Z]$"

It only matches BettyX.

Thank you,

\\b([A-Z])+([a-zA-Z]+)?([A-Z])\\b

Actually that one works as well, I must have misspelled something before.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.