New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snake_case to camelCase fails to match `_[letter][number]` #714

brycethomas opened this Issue Mar 22, 2017 · 1 comment


None yet
2 participants

brycethomas commented Mar 22, 2017

issue in the master revision at time of writing:

camelCase(time_t0) --> timeT0 (expected)
camelCase(time_t0) --> time_t0 (actual)


From parse.js, copy this snippet into Chrome dev tools:

var camelCaseRe = /_([a-z])(?=[a-z]|$)/g;

function camelCase(str) {
    return str.substring(0,1)
         + str.substring(1)
               .replace(camelCaseRe, function($0, $1) { return $1.toUpperCase(); });

Then evaluate:


Root Cause

The issue is that the second regex capture group doesn't include numbers; note that the current regex works fine where two or more letters precede the number:

camelCase('time_t0') --> time_t0 (incorrect)
camelCase('time_tt0') --> timeTt0 (correct)

Not sure why the current regex checks two characters after the underscore—could it perhaps be reworked to only check the one? cf. Google's C++ implementation, which simply checks that the letter immediately following the underscore is in range a-z:

dcodeIO added a commit that referenced this issue Mar 22, 2017

@dcodeIO dcodeIO added the bug label Mar 22, 2017


This comment has been minimized.


dcodeIO commented Mar 22, 2017

Should be fixed in master. Feel free to reopen if there are any remaining issues!

@dcodeIO dcodeIO closed this Mar 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment