0

I am implementing ESLint id-match rule and I want to enforce camelCase convention.

I have now came up with ^[a-z]+(?:[A-Z][a-z]*)*\d*$ that is used to validate:

fooB
fooBar
fooBarBaz
foo123
fooBar123

and that does not validate:

foo123Bar
foo_bar
foo$
föö

Is this a correct regex to validate compatibility with the camelCase convention?

Gajus
  • 69,002
  • 70
  • 275
  • 438
  • 1
    http://stackoverflow.com/questions/1128305/regular-expression-to-identify-camelcased-words see here for more elaborate answers – mahatmanich Aug 21 '15 at 08:18
  • 1
    @mahatmanich Thank you. Closing as a duplicate. – Gajus Aug 21 '15 at 08:20
  • 1
    For those who will come across this while searching for a regex for ESLint id-match rule, I have ended up using `(^[A-Za-z]+(?:[A-Z][a-z]*)*\d*$)|(^[A-Z]+(_[A-Z]+)*(_\d$)*$)|(^(_|\$)$)` rule (https://regex101.com/r/wR5oZ4/3). It validates variable and property names, class names, common utility names (`_` and `$`) and constants. I have shared my entire ESLint rule definition here, github.com/gajus/eslint-rules/blob/master/.eslintrc. – Gajus Aug 21 '15 at 08:34

0 Answers0