in reply to Re: Regex simplification
in thread [untitled node, ID 192753]

I'd do it like this:
$line = '<!-- USER 20 - donkey_pusher_6 -->'; print $1 if $line =~ m/<!-- USER \d+ - ([^\s]+)/i;
because you might get false-positive matches the other way.
--
($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;

Replies are listed 'Best First'.
Re: Re: Re: Regex simplification
by Thelonius (Priest) on Aug 26, 2002 at 03:53 UTC
    print $1 if $line =~ m/<!-- USER \d+ - ([^\s]+)/i;
    This is good, but it \S is shorter than [^\s], so:
    print $1 if $line =~ m/<!-- USER \d+ - (\S+)/i;
    Although to get a little closer to the original specification, I'd put:
    my $user=undef; for (@site) { if (/<!--.*USER.* (\S+) -->/) { print "joe:\n"; $user = $1; last; } } print "user = $user\n";