in reply to Regex Needed

m/(\w+) (?=FOUND)/g;

have a look at perldoc perlre   where look-ahead is mentioned. The example there quite matches your problem.

Replies are listed 'Best First'.
Re: Re: Regex Needed
by TilRMan (Friar) on Mar 25, 2004 at 02:15 UTC

    I think the OP has a different definition of "word" than Perl does -- in particular, a word can contain a colon. My guess is that the OP wants a word to be any non-whitespace.

    m/(\S+)\s+FOUND/; # The word is now in $1

    I don't see the need to use lookahead for this regex.

    -- 
    LP^>

Re: Re: Regex Needed
by ysth (Canon) on Mar 25, 2004 at 02:07 UTC
    That would work, but if the goal is to have the entire match ($&) be the desired word, it should be
    m/\w+(?= FOUND)/g
    If capturing into $1 is the goal,
    m/(\w+) FOUND/g
    is all that is needed.