降低字符并替换指定字符

Contents

输出结果

a_b_c


程式码


JavaScript

let str = "A-B-C";
console.log(str.replace(/-/g, "_").toLowerCase());

PHP

<?php
$str = "A-B-C";
echo strtolower(preg_replace("/-/", "_", $str))."\n";

Perl

my $str="A-B-C";
$str=~ s!-!_!gs;
print lc($str)."\n";

Python

str = "A-B-C"
print(str.replace("-", "_").lower())

Ruby

str = "A-B-C"
print(str.gsub("-", "_").downcase+"\n")