[EMAIL PROTECTED] writes:
 > Hi, i have this:
 > $toto1="Transitionned to assigned by lmiso to W_VAL3G_SOP on 29/11/2001
 > 15:20:46";
 > $toto2="Transitionned to concluded by elohez on 1/2/2002 7:47:31";
 > 
 > 
 > $toto1=~/^Transitionned to ([^ ]*) by ([^ ]*)( to ([^ ]*))? on ([^ ]*)/;
 > 
 > print "$1\n";
 > print "$2\n";
 > print "$3\n";
 > 
 > $toto2=~/^Transitionned to ([^ ]*) by ([^ ]*)( to ([^ ]*))? on ([^ ]*)/;
 > print "$1\n";
 > print "$2\n";
 > print "$3\n";
 > 
 > but it didn't work i wanted what is coming after "Transitionned to" "by"
 > "to"(if it exists) and "on".
 > 
 > Could you help me.

Actually you regex is working better than you think, but you are not
looking in the right place. Your regex has 5 pairs of brackets
therefor it will collect 5 substrings on a successful match (even for
the optional part), but you are only looking at the first 3.

Try the following (I have improved your regex slightly):

----------------------------------------
use strict;
use warnings;

my $regex = qr{^Transitionned to (\S+) by (\S+)( to (\S+))? on (\S+)};
my $toto1="Transitionned to assigned by lmiso to W_VAL3G_SOP on 29/11/2001 15:20:46";
my $toto2="Transitionned to concluded by elohez on 1/2/2002 7:47:31";


my @results = $toto1 =~ /$regex/;
print "'", join("', '", @results), "'\n";

@results = $toto2=~/$regex/;
print "'", join("', '", @results), "'\n";
----------------------------------------

Note that the second print produces some warnings about uninitialised
values due to the 'to' clause not being present.

If you want to avoid collecting the whole 'to' clause, try the
following changes:

my $regex = qr{^Transitionned to (\S+) by (\S+)(?: to (\S+))? on (\S+)};

my ($state, $by, $to, $date) = $toto1 =~ /$regex/;
$to = "<unknown>" unless defined $to;
print "state: $state by: $by to: $to date: $date\n";

($state, $by, $to, $date) = $toto2=~/$regex/;
$to = "<unknown>" unless defined $to;
print "state: $state by: $by to: $to date: $date\n";

See 'perldoc perlre' for lots more info about regex stuff.

HTH

-- 
Brian Raven

Perl did not get where it is by ignoring psychological factors.
             -- Larry Wall in <[EMAIL PROTECTED]>


-----------------------------------------------------------------------
The information contained in this e-mail is confidential and solely 
for the intended addressee(s). Unauthorised reproduction, disclosure, 
modification, and/or distribution of this email may be unlawful. If you 
have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message 
do not necessarily reflect those of 
LIFFE Holdings Plc or any of its subsidiary companies.
-----------------------------------------------------------------------

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to