in reply to Re: Excluding Words in RegEx
in thread Excluding Words in RegEx

In the OP an example line starting with a four digit number is given. The OP gives a regex for capturing the number and the rest of the line separately but is asking how to skip lines containing 'group' at the same time. ikegami gave a good response.

Replies are listed 'Best First'.
Re^3: Excluding Words in RegEx
by CountZero (Bishop) on Nov 06, 2011 at 16:29 UTC
    That is exactly why I said that the requirement could not have been that simple. Another example of an "XY-problem"!

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re^3: Excluding Words in RegEx
by dominic01 (Sexton) on Nov 07, 2011 at 04:08 UTC

    It is not that simple I suppose. But ikegami code works great.

    my $Line = "1243 That will efficiently match a nonempty group with mat +ching parentheses two levels deep or less."; if ($Line =~ /^(?!.*\bgroup\b)(\d{4}) ([^.]+?[.\!\?])$/){ print "$1\n$2\n"; #Does not print } elsif ($Line =~ /^(?!.*\bgXroup\b)(\d{4}) ([^.]+?[.\!\?])$/){ print "$1\n$2\n"; #Prints }

    Though it solves my original query just wondering if it is possible to check the word in the second group of (). Thanks ramprasad27 for the "\." point. I didnt know that earlier.

    -Dominic