一些 Perl 示例:
my $str = 'variable_name, VARIABLE_NAME, _var_x_short, __variable__name___';
### solution 1
$_ = $str;
$_ = lc;
s/_(\w)/\U$1/g;
say;
### solution 2: multi/leading underscore fix
$_ = $str;
$_ = lc;
s/(?<=[^\W_])_+([^\W_])|_+/\U$1/g;
say;
### solution 3: without prior lc
$_ = $str;
s/(?<=[^\W_])_+([^\W_])|([^\W_]+)|_+/\U$1\L$2/g;
say;
输出:
variableName, variableName, VarXShort, _variable_name__
variableName, variableName, varXShort, variableName
variableName, variableName, varXShort, variableName