j'avais utiliser le "RegexDesigner" de RadSoftware et c'est lui qui a un
problème.
Tiens, un chouette outil d'aide aux regex en perl, lui ( avec Tk):
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
my $mw = MainWindow->new;
my $menubar = $mw->Menu(-type => 'menubar');
$mw->configure(-menu => $menubar);
{
my $f = $menubar->cascade(-label => '~File', -tearoff => 0);
$f->command(-label => "Open...", -command => \&open_cmd);
$f->separator();
$f->command(-label => "~Quit", -command => sub {$mw->destroy()});
}
$mw->Entry(qw/-validate key -width 50 -bg white -fg black/,
-validatecommand => \&try_match,
-textvariable => \my $reg)
->pack(qw/-fill x/);
$mw->Label(-textvariable => \my $err, qw/-fg red -justify left/)
->pack(qw/-fill x/);
my $text =
$mw->Scrolled('Text', qw/-scrollbars se -bg white -fg black -wrap none/)
->pack(qw/-fill both -expand 1/);
$text->tagConfigure('0', qw/-background green/);
$text->tagConfigure('1', qw/-background cyan/);
MainLoop;
sub try_match {
my ($regexp, $tag, $null, $match) = (shift, 0, 0, 0);
$text->tagRemove(0, '0.0', 'end');
$text->tagRemove(1, '0.0', 'end');
$err = "";
return 1 if $regexp eq "";
eval {
"" =~ m/$regexp/;
my $start = "0.0";
while (defined (my $first =
$text->search(qw/-regexp -forwards/,
-count => \ (my $count),
$regexp, $start, 'end'))) {
$match ++;
if ($count == 0) {
$null++;
$start = $text->index("$first +1 chars");
last if $text->compare($start, ">=", 'end');
} else {
$start = $text->index("$first +$count chars");
$text->tagAdd($tag = 1 - $tag, $first, $start);
}
}
};
if ($@) {
($err = $@) =~ s/;.*//s;
} elsif ($null) {
$err = "$match occurrence(s) ($null null string(s))";
} else {
$err = "$match occurrence(s)";
}
return 1;
}
sub open_cmd {
my $file = $mw->getOpenFile(-filetypes => [['Text' => '.txt'],
['All' => '.*']]);
return if not defined $file or not -r $file;
local $/ = undef;
open my $fh, "<", $file
or $err = "Can't read file '$file': $!", return;
my $content = <$fh>;
close $fh;
$text->delete('0.0', 'end');
$text->insert('0.0', $content);
try_match($reg);
}
--
Quis, quid, ubi, quibus auxiliis, cur, quomodo, quando