Alex Rivera | Logout

What Perl regex can match CamelCase words?

Asked 2009-05-02T22:35:40.080
11

I am searching the following words in .todo files:

ZshTabCompletionBackward 
MacTerminalIterm

I made the following regex

[A-Z]{1}[a-z]*[A-Z]{1}[a-z]*

However, it is not enough, since it finds only the following type of words

ZshTab

In pseudo code, I am trying to make the following regex

([A-Z]{1}[a-z]*[A-Z]{1}[a-z]*){1-9}

How can you make the above regex in Perl?

Edit
Report

2 Answers

8

Assuming you aren't using the regex to do extraction, and just matching...

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

Isn't the only real requirement that it's all letters and starts with a capital letter?

answered 2009-05-03T01:21:29.167
0

Use this one:

/\b[A-Z]([a-z]+[A-Z]?)*\b/
answered 2009-07-15T20:29:48.040

Your Answer