perl正则表达式--小写变大写
以下代码可以将SQL语句中的关键字改为大写,如create改为CREATE,Order改为ORDER,disTinCt改为DISTINCT,另外特别注意的是只有perl才支持/U替换选项use strict;
use warnings;
my $str;
$str="where create Order By disTinCt";
if ($str=~ /(where|create|Order|By|disTinCt)/)
{
#$str =~s/(^|\W*)(\w*)/$1\u$2/g;//首字母大写
$str =~s/(where|create|Order|By|disTinCt)/\U$1/g;
print $str . "\n";
}
页:
[1]