in reply to Excluding Words in RegEx

How do I achieve in a single regex?

Why?

if ($Line !~ /\bgroup\b/ && $Line =~ /^(\d{4}) ([^\.]+?[\.\!\?])$/)

But it can be done.

if ($Line =~ /^(?!.*\bgroup\b)(\d{4}) ([^\.]+?[\.\!\?])$/)

Replies are listed 'Best First'.
Re^2: Excluding Words in RegEx
by ramprasad27 (Sexton) on Nov 06, 2011 at 07:02 UTC
    should we need to escape . ?

    /^(?!.*\bgroup\b)(\d{4}) (^.+?.\!\?)$/

    is good enough? \. and . does the same thing? any takers?

      Good point that within a character class '.' does not need to be escaped with a backslash. However, you need to use <code></code> tags around it in your post so the [] aren't rendered as links.

      I just copied the OP's pattern. But yeah,
      /^(\d{4}) ([^\.]+?[\.\!\?])$/

      can be shortened to

      /^(\d{4}) ([^.]+?[.!?])$/