1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| sub Regex {
if ( !$Regex ) {
$LabRegex = "Regex vide !";
$LabMessage = "Regex vide !";
print "\a\a";
return;
}
$TexteInput = $widget_input->get( '1.0', 'end' );
my $Pattern = $Regex;
$Pattern =~ s/ /\\ /go;
$LabRegex = $Pattern;
my $i = 0;
my @Array = ($TexteInput =~ m/(\b.{0,40}$Pattern.{0,40}\b)/gx);
my $Nb = @Array;
if ($Nb == 1){
my @NewArray = split /$Pattern/, $TexteInput;
my @ChainePref = ( $Array[0] =~ m/($Pattern)/gx);
$widget_output->insert( 'end', $NewArray[0] );
$widget_output->see( 'end' );
$widget_output->update;
$widget_output->tagAdd( 'MARK', 'end -1 chars' );
my @Mark = $widget_output->tagRanges( 'MARK' );
my ($SelA, $SelB) = split /\./, $Mark[0];
$SelB = $SelB + length($ChainePref[0]);
my $SelLast = $SelA.".".$SelB;
print "MARK=$Mark[0] SELLAST=$SelLast\n";
$widget_input->see( $Mark[0] );
$widget_output->insert( 'end', $ChainePref[0], "g14");
$widget_input->tagAdd( 'g14', $Mark[0], $SelLast);
$widget_input->update;
$widget_output->insert( 'end', $NewArray[1] );
$LabRegex = $Pattern;
} else {
foreach my $Ligne ( @Array ) {
$widget_output->insert( 'end', ++$i .": ".$Ligne."\n" );
}
}
} |
Partager