What Perl regex can match CamelCase words? -
I'm searching the following words in .odod files:
ZshTabCompletionBackward MacTerminalIterm I created the following regex
[az] {1} [az] * [az] {1} [az] * However, this is not enough, because it only finds the following types of words
ZshTab In the phony code, I'm trying Am
I think you want something like this, to add written comments and trivial white space < With the code> / x flag:
/ \ b # the word limit so that you do not start in the middle of a word (# open group [es] # initial uppercase [az] * # Any number lowercase letters) # End grouping {2,} # quantifier: at least 2 instances, unlimited maximum of the words # x limit / x if you want it without fancy formattingOnly remove spaces and comments: As j_random_hacker points out:
/ \ b ([AZ] [Az] *) {2,} \ b / It is simple because it will match a word that is the only constant capital letter. His solution, which I have expanded in detail with / x , ensures at least one lowercase letter:
/ \ b # on word limit Beginning [AG] # Start with # Non-Capturing Grouping for any alpha (?: #changes preceding [AG] [A-GA-Z] * [AGED] # after start [a-zA-Z] * # # The next bit is low, zero or more, ending with upper # or [az] [A-GA-Z] * [as] # next bit is upper, zero Or more, at least) [A-GA-Z] * # # and Word / X
If you want it without fancy formatting, just remove the spaces and comments : [AZ] [a-zA-Z] * (?: [Ez] [A-GA-Z] * [AGED] | [AGED] [A-GA-Z] * [Ez]) [A-GAAA-Z] * B /
I explain all these features.
Comments
Post a Comment