Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Python

r"
^ ( # Match one of these: [A-Z]?[a-z]+| # A possibly-capitalized identifier, or: [A-Z]+ # An ALL CAPS identifier... (?![a-z]) # ...not immediately followed by lowercase ) # and capture the rest of the string (.*?) $
"
xgm

Description

Helper regex for parsing CamelCase identifiers. Captures the first word of the identifier in group 1 and the rest in group 2. Iterate to consume the whole name. Works on fooBar, FooBar, and FOOBar.

Submitted by Kevin - 10 years ago