#!/usr/bin/perl #replace_selected use strict; use Encode qw(from_to); my $inHTMLText = $ARGV[1]; &from_to( $inHTMLText, 'utf-8', 'euc-jp' ); #'shiftjis' 'utf-8' #属性値を小文字にする属性を書く my %lcAttrDic = ( 'type'=>1, 'clear'=>1, 'align'=>1, 'valign'=>1, 'color'=>1, ); &run(); sub run { $inHTMLText =~ s/(<\w+\s*)(.*?>)/ lc( $1 ) . &lcAllAttr($2)/gie; $inHTMLText =~ s!()! lc($1) !gie; print $inHTMLText; } sub lcAllAttr { my $inAllAttr = shift; $inAllAttr =~ s/(\s*)([A-Z]+)(=".*?"|=\w+|\s|>)/ $1 . lcOneAttr( $2, $3 ) /gie; return $inAllAttr; } sub lcOneAttr { my $inAttr = shift; my $inValue = shift; $inAttr = lc( $inAttr ); if( $lcAttrDic{ $inAttr } ) { $inValue = lc( $inValue ); } return $inAttr . $inValue; }