use strict; use warnings; my @tests = ( { str => q{423RY75Y69827EC67592C78657N965R}, ans => q{423R_Y75Y_69827E_C67592C_78657N965R} }, { str => q{423RY75Y69827EC67592C78657N965R345U299M}, ans => q{423R_Y75Y_69827E_C67592C_78657N965R_345U_299M} }); my $rxDigit = qr{[N0-9]}; my $rxNonDigit = qr{[A-MO-Z]}; foreach my $rhTest (@tests) { (my $myAns = $rhTest->{str}) =~ s{((?:$rxDigit)+$rxNonDigit)(?!\z)}{$1_}g; print qq{\n$rhTest->{str}\n}, $myAns eq $rhTest->{ans} ? qq{OK\n} : qq{Not OK\n}, qq{$myAns\n}, qq{$rhTest->{ans}\n}; }
Here is the output.
423RY75Y69827EC67592C78657N965R OK 423R_Y75Y_69827E_C67592C_78657N965R 423R_Y75Y_69827E_C67592C_78657N965R 423RY75Y69827EC67592C78657N965R345U299M OK 423R_Y75Y_69827E_C67592C_78657N965R_345U_299M 423R_Y75Y_69827E_C67592C_78657N965R_345U_299M
I hope this is of use.
Cheers,
JohnGG
In reply to Re: match if last char and first char are different excluding certain chars
by johngg
in thread match if last char and first char are different excluding certain chars
by leocharre
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |