开发者

RegEx for matching alternating case letters

开发者 https://www.devze.com 2022-12-27 01:07 出处:网络
I would like to detect the following sequences: a aA aAa aAaA ... where a~[a-z] and A~[A-Z], the case alternates and the first letter is always lower-case.

I would like to detect the following sequences:

a
aA
aAa
aAaA
...

where a~[a-z] and A~[A-Z], the case alternates and the first letter is always lower-case.

开发者_JAVA技巧

Thanks,

Tom


[a-z]([A-Z][a-z])*[A-Z]?


The regex that @tanascius gave is fine, and based on that, a shorter one could be:

([a-z][A-Z])*[a-z]?

A major difference is that this one will match the empty string. I wasn't sure from the examples if that was allowed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号