简体   繁体   English

是否有替代sed或vim的\\ l和\\ u的perl?

[英]Is there a perl equivalent to sed's or vim's `\l` and `\u` in substituting?

in sed(1) & vim(1) , there are a set of 'operators' in the regex substitution syntax, \\u\u003c/code> , \\l , \\U , & \\L . sed(1)vim(1) ,正则表达式替换语法中有一组'operators', \\u\u003c/code> , \\l\\U\\L These translit characters to either lowercase, or uppercase. 这些字符转换为小写或大写。 So if one were to type s/(*.)/\\L\\1/g , it would translit the entire string to lowercase, theoretically. 因此,如果要键入s/(*.)/\\L\\1/g ,理论上它将把整个字符串转换为小写。

Is there equivalent functionality in Perl? Perl中是否有等效的功能? Is something or eqivalent like... 是类似的东西...

while(<>) {
  s/(*.)/\L\1/g;
}

vaild? 可以吗?

Yes, all of them exist in Perl. 是的,它们全部都存在于Perl中。

But your regex is invalid, I guess you want: 但是您的正则表达式无效,我想您想要:

while(<>) {
  s/(.*)/\L$1/g;
}

If you want to lowercased the whole string, I suggest you lc : 如果要对整个字符串进行小写,建议您使用lc

while(<>) {
  $_ = lc $_;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM