in reply to regex clarification

Of course there are going to be many ways to do this. Here's one:

while (<>) { push(@array, $1) if m/^(\w+)\s+(?!Vet)\S/; } print @array;

What this has going for it is that it doesn't use $& (the use of which is a considerable performance hit). Also, it doesn't use (?>pattern) which is: "considered highly experimental, and may be changed or deleted without notice." see perldoc perlre (of course) for more details.

Replies are listed 'Best First'.
Re^2: regex clarification
by tphyahoo (Vicar) on Mar 05, 2005 at 11:55 UTC
    Thelonius, for some reason that "not space" at the end of your regex seems weird to me.

    I like this solution, because it's an easy way to rule out lines that contain something (ie, "vet") anywhere after the first word, which is I think what the OP really wants to do.

    while (<DATA>) { # match the first word # in lines that don't contain "vet" anywhere push(@array, $1) if m/^(?!\w+\b.*vet)(\w+)/i; } print("@array\n"); __DATA__ David Veterinarian Jackie Orthopedist Karen Veterinarian Vetch Orthopedist Vetch Veterinarian