1 my $string = '"hello there", said Pooh, "how are you today?". I said "brilliant!".';
2 print "$string\n";
3 $string =~ s/('|")(.*?)\1/$1.uc($2).$1/ge;
4 print "$string\n";
I want to change letters in ' or '' to be uppercase. Without the ? the result will not be correct. Note that * is greedy and ? is not greedy.
本文通过一个Perl脚本示例展示了如何使用正则表达式来匹配并转换字符串中的特定部分,特别是将某些字符转换为大写。
220

被折叠的 条评论
为什么被折叠?



