[Question]
  [
# The Challenge
I was reading [Google's Java Style Guide](https://google.github.io/styleguide/javaguide.html#s5.3-camel-case) the other day and stumbled over their algorithm to convert any arbitrary string into camelCase notation. In this challenge you have to implement this algorithm since you don't want to do all this stuff in your head when you are writing your super competitive Java submissions to code-golf challenges.
*Note: I made some small adjustments to the algorithm. You need to use the one specified below.*
# The algorithm
You start with an arbitrary input string and apply the following operations to it:
1. Remove all apostrophes ``'`
2. Split the result into words by splitting at
* characters that are not alphanumerical and not a digit `[^a-zA-Z0-9]`
* Uppercase letters which are surrounded by lowercase letters on both sides. `abcDefGhI jk` for example yields `abc Def Ghi jk`
3. Lowercase every word.
4. Uppercase the first character of every but the first word.
5. Join all words back together.
### Additional notes
* The input will only contain printable ASCII.
* If a digit is the first letter in a word, leave it as it is and don't capitalize something else in this word.
* The input will always have at least one character.
# Rules
* Function or full program allowed.
* [Default rules](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods) for input/output.
* [Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) apply.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so lowest byte-count wins. Tiebreaker is earlier submission.
# Test cases
```
"Programming Puzzles & Code Golf" -> "programmingPuzzlesCodeGolf"
"XML HTTP request" -> "xmlHttpRequest"
"supports IPv6 on iOS?" -> "supportsIpv6OnIos"
"SomeThing w1th, apo'strophe's and' punc]tuation" -> "someThingW1thApostrophesAndPuncTuation"
"nothing special" -> "nothingSpecial"
"5pecial ca5e" -> "5pecialCa5e"
"1337" -> "1337"
"1337-spEAk" -> "1337Speak"
"whatA mess" -> "whataMess"
"abcD" -> "abcd"
"a" -> "a"
"B" -> "b"
```
**Happy Coding!**
  
[Answer]
## [Retina](https://github.com/mbuettner/retina), 56 bytes
Byte count assumes ISO 8859-1 encoding.
```
T`'\`
S_`\W|_|(?<=[a-z])(?=[A-Z][a-z])
T`L`l
T`l`L`¶.
¶
```
[Try it online!](http://retina.tryitonline.net/#code=VGAnXGAKU19gXFd8X3woPzw9W2Etel0pKD89W0EtWl1bYS16XSkKVGBMYGwKVGBsYExgwrYuCsK2Cg&input=IVNvbWVUaGluZyB3MXRoLCBhcG8nc3Ryb2BwaGUncyBhbkQnIHB1bmNddHVhVElvbg)
### Explanation
This implements the specification quite literally:
```
T`'\`
```
Remove apostrophes and backticks.
```
S_`\W|_|(?<=[a-z])(?=[A-Z][a-z])
```
Split the string around non-word characters (in regex this also excludes digits and underscores), or underscores or positions that have a lower case letter on the left and and upper case, lower case on the right. This would create some empty segments when there are two non-letter, non-digit characters in a row, or more important at the beginning of the string. We get rid of those with the `_` option. Here, "splitting" means put each remaining part on its own line.
```
T`L`l
```
Convert everything to lower case.
```
T`l`L`¶.
```
Convert each character that occurs after the linefeed to upper case. This will conveniently skip the first word because there's no linefeed in front of it.
```
¶
```
Get rid of the linefeeds to join everything back together.
[Answer]
## Java, ~~198~~ 190 bytes
*+3 bytes because I forgot that `\W+` == `[^a-zA-Z0-9_]+` and I need to match `[^a-zA-Z0-9]+`*
-11 bytes thanks to [user20093](https://codegolf.stackexchange.com/users/20093/user902383) - `?:` instead of `if`/`else`
[Because, Java.](http://meta.codegolf.stackexchange.com/a/5829)
```
s->{String[]a=s.replaceAll("`|'","").split("[\\W_]+|(?<=[a-z])(?=[A-Z][a-z])");s="";for(String w:a){String t=w.toLowerCase();s+=a[0]==w?t:t.toUpperCase().charAt(0)+t.substring(1);}return s;}
```
This is a lambda. Call like so:
```
UnaryOperator<String> op = s->{String[]a=s.replaceAll("`|'","").split("[\\W_]+|(?<=[a-z])(?=[A-Z][a-z])");s="";for(String w:a){String t=w.toLowerCase();s+=a[0]==w?t:t.toUpperCase().charAt(0)+t.substring(1);}return s;};
System.out.println(op.apply("Programming Puzzles & Code Golf"));
```
Readable version:
```
public static String toCamelCase(String s) {
    String[] tokens = s
            .replaceAll("`|'", "") // 1. Remove all apostrophes
            .split("[\\W_]+|(?<=[a-z])(?=[A-Z][a-z])"); // 2. Split on [\W_]+ or between [a-z] and [A-Z][a-z]
    s = ""; // Reusing s for building output is cheap
    for (String token : tokens) {
        String lowercaseToken = token.toLowerCase(); // 3. Lowercase every word
        s += tokens[0].equals(token)?lowercaseToken:lowercaseToken.toUpperCase().charAt(0) + lowercaseToken.substring(1); // 4. Uppercase first char of all but first word
        // ^ 5. Join all words back together
    }
    return s;
}
```
[Answer]
# JavaScript (ES6), ~~156~~ ~~154~~ ~~152~~ ~~148~~ ~~145~~ ~~141~~ 140 bytes
*Thanks @Neil (6 bytes), @ETHproductions (3 bytes), and @edc65 (7 bytes)*
```
a=>a[r='replace'](/`|'/g,a='')[r](/[a-z](?=[A-Z][a-z])/g,'$& ')[r](/[^\W_]+/g,b=>a+=(a?b[0].toUpperCase():'')+b.slice(!!a).toLowerCase())&&a
```
Removes apostrophes, then does a replace to split on special characters/before surrounded capitals, then combines with proper casing. Unfortunately, `toLowerCase()` and `toUpperCase()` are annoyingly long and hard to avoid here...
[Answer]
## vim, ~~69~~ ~~68~~ 66
```
:s/[`']//g<cr>:s/[a-z]\zs\ze[A-Z][a-z]\|\W\|_/\r/g<cr>o<esc>guggj<C-v>GgU:%s/\n<cr>
```
vim shorter than Perl?! What is this madness?
```
:s/[`']//g<cr>           remove ` and '
:s/                      match...
 [a-z]\zs\ze[A-Z][a-z]   right before a lowercase-surrounded uppercase letter
 \|\W\|_                 or a non-word char or underscore
 /\r/g<cr>               insert newlines between parts
o<esc>                   add an extra line at the end, necessary later...
gugg                     lowercasify everything
j                        go to line 2 (this is why we added the extra line)
<C-v>G                   visual select the first char of all-but-first line
gU                       uppercase
:%s/\n<cr>               join all lines into one
```
Thanks to [Neil](https://codegolf.stackexchange.com/users/17602/neil) for spotting a useless keystroke!
[Answer]
## Mathematica 10.1, 101 bytes
```
""<>(ToCamelCase@{##2}~Prepend~ToLowerCase@#&@@StringCases[StringDelete[#,"`"|"'"],WordCharacter..])&
```
Uses the undocumented `ToCamelCase`, which works similarly to `Capitalize` but sets other characters to lowercase.
[Answer]
# Julia, ~~98~~ 89 bytes
```
s->lcfirst(join(map(ucfirst,split(replace(s,r"['`]",""),r"[a-z]\K(?=[A-Z][a-z])|\W|_"))))
```
This is an anonymous function that accepts a string and returns a string. To call it, assign it to a variable.
The approach here is the same as in Doorknob's [Perl answer](https://codegolf.stackexchange.com/a/74658/20469): `replace` apostrophes and backticks with the empty string, `split` into an array on a regular expression that matches the necessary cases, `map` the `ucfirst` function over the array to uppercase the first letter of each element, `join` the array back into a string, and `lcfirst` the result to convert the first character to lowercase.
[Answer]
# Perl 67 + 1 = 68 bytes
```
y/'`//d;s/([a-z](?=[A-Z][a-z]))|\W|_/$1 /g;$_=lc;s/^ +| +(.)/\u$1/g
```
Requires the `-p` flag, and `-l` for multi line:
```
$ perl -pl camelCase.pl input.txt
programmingPuzzlesCodeGolf
xmlHttpRequest
supportsIpv6OnIos:
someThingW1thApostrophesAndPuncTuation
nothingSpecial
5pecialCa5e
1337
1337Speak
abcd
```
How it works:
```
y/'`//d;                            # Remove ' and `
s/([a-z](?=[A-Z][a-z]))|\W|_/$1 /g; # Replace according to '2. Split...' this will create
                                    #   a space separated string.
$_=lc;                              # lower case string
s/^ +| +(.)/\u$1/g                  # CamelCase the space separated string and remove any
                                    #   potential leading spaces.
```
[Answer]
# Lua, 127 Bytes
```
t=''l=t.lower z=io.read()for x in z:gmatch('%w+')do t=t..(t==''and l(x:sub(1,1))or x:sub(1,1):upper())..l(x:sub(2))end return t
```
Accepts a string from stdin and returns camelized results.
Probably still gonna look for a better solution as storing everything in a variable feels inefficient.
But anyhow, pretty simple in general:
```
 z:gmatch('%w+')
```
This is the beauty that saved me a bit of bytes. gmatch will split the string based on the pattern: `%w+` which grabs only alphanumerics.
After that it's simple string operations. string.upper, string.lower and done.
[Answer]
# PHP, ~~145~~ ~~122~~ 133 bytes
```
<?=join(split(" ",lcfirst(ucwords(strtolower(preg_replace(["#`|'#","#\W|_#","#([a-z])([A-Z][a-z])#"],[""," ","$1 $2"],$argv[1]))))));
```
Save to file, call from CLI.  
Takes input from a single command line argument; escape quotes and whitespace where necessary.
**breakdown**
```
<?=                 // 9. print result
join(split(" ",     // 8. remove spaces
    lcfirst(        // 7. lowercase first character
    ucwords(        // 6. uppercase first character in every word
    strtolower(     // 5. lowercase everything
    preg_replace(
        ["#`|'#",   "#\W|_#",   "#([a-z])([A-Z][a-z])#"],
        ["",        " ",        "$1 $2"],
        // 2. replace apostrophes with empty string (remove them)
                    // 3. replace non-word characters with space
                                // 4. insert space before solitude uppercase
        $argv[1]    // 1. take input from command line
    ))))
));
```
`lcfirst` allowed to reduce this to a single command, saving 23 bytes.  
Fixing the apostrophes cost 11 bytes for the additional replace case.
[Answer]
## Perl, ~~87~~ ~~80~~ 78 bytes
```
y/'`//d;$_=join'',map{ucfirst lc}split/[a-z]\K(?=[A-Z][a-z])|\W|_/,$_;lcfirst
```
Byte added for the `-p` flag.
First, we use the `y///` transliteration operator to `d`elete all `'`` characters in the input:
```
y/'`//d;
```
Then comes the meat of the code:
```
                         split/[a-z]\K(?=[A-Z][a-z])|\W|_/,$_;
```
(split the input string `$_` in the appropriate locations, using the fancy `\K` in the match string to exclude the portion preceding it from the actual match)
```
          map{ucfirst lc}
```
(map over each split portion of the string and make the entire string lowercase, then make the first character of the modified string uppercase)
```
$_=join'',
```
(join on empty string and re-assign to magic underscore `$_`, which gets printed at the end)
Finally, we lowercase the first letter ~~by regex-matching it and using `\l` in the replacement string~~ with a builtin, saving 2 bytes over the previous method:
```
lcfirst
```
Thanks to [@MartinBüttner](https://codegolf.stackexchange.com/users/8478/martin-b%c3%bcttner) for 7 bytes (`[^a-zA-Z\d]` -> `\W|_`)!
[Answer]
# [Kotlin](https://kotlinlang.org/), 160 Bytes
```
fun a(s: String)=s.replace(Regex("['`]"),"").split(Regex("[\\W_]+|(?<=[a-z])(?=[A-Z][a-z])")).map{it.toLowerCase().capitalize()}.joinToString("").decapitalize()
```
My goal was to be Scala, the other "alternative Java", so I'm somewhat happy with my results. I stole the regex from the [Java](https://codegolf.stackexchange.com/a/74684/20198) answer.
Test it with:
```
fun main(args: Array<String>) {
    val testCases = arrayOf(
            "Programming Puzzles & Code Golf",
            "XML HTTP request",
            "supports IPv6 on iOS?",
            "SomeThing w1th, apo'strophe's and' punc]tuation",
            "nothing special",
            "5pecial ca5e",
            "1337",
            "1337-spEAk",
            "abcD",
            "a",
            "B")
    testCases.forEach { println(a(it)) }
}
```
[Answer]
# Scala, ~~181~~ ~~170~~ 144
```
def f(s:String)={val l=s.replaceAll("'|`","")split("[\\W_]+|(?<=[a-z])(?=[A-Z][a-z])")map(_.toLowerCase);l(0)+l.tail.map(_.capitalize).mkString}
```
Tester:
```
val testCases = List(
  "Programming Puzzles & Code Golf" -> "programmingPuzzlesCodeGolf",
  "XML HTTP request" -> "xmlHttpRequest"
  // etc
)
println(testCases.map(t=>if(t._2!=f(t._1))s"FAIL:${f(t._1)}"else"PASS").mkString("\n"))
```
Props to [CAD97](https://codegolf.stackexchange.com/users/51825/cad97) and apologies to [Nathan Merrill](https://codegolf.stackexchange.com/users/20198/nathan-merrill) :)
[Answer]
# C 272 characters
C program pass string to camelCase in quotes as argument 1. There are lot's of gotchas in this problem statement...
```
#define S strlen(t)
#define A isalnum(t[i])
j=0;main(i,v)char**v;{char*p=v[1],*t;char o[99]={0};while(t=strtok(p," [{(~!@#$%^*-+=)}]")){i=0;p+=S+1;while((!A)&&i<S)i++;if(i!=S){o[j]=((j++==0)?tolower(t[i++]):toupper(t[i++]));while(i<S){if(A)o[j++]=t[i];i++;}}}puts(o);}
```
[Answer]
# JavaScript, 123 bytes
```
v=>v[r="replace"](/[`']/g,"")[r](/^.|.$|[A-Z][^a-z]+/g,x=>x.toLowerCase())[r](/[^a-z0-9]+./ig,x=>x.slice(-1).toUpperCase())
```
Readable version
```
v=>
  v.replace(/[`']/g,"")
  .replace(/^.|.$|[A-Z][^a-z]+/g,x=>x.toLowerCase())
  .replace(/[^a-z0-9]+./ig,x=>x.slice(-1).toUpperCase())
```
Remove the apostrophes, 
make the first character lower case, the last character lowercase, and any grouping of multiple uppercase characters,
match any group of 1 or more non-alphanumeric chars + 1 other character, replace with that last character capitalized.
[r="replace"] trick from Mrw247's solution.
]