in reply to Help Me Understand This Regex

There is a module YAPE::Regex::Explain which can help you to understand regular expressions. Here the output for your expression:
The regular expression: (?-imsx:(?:(?<=\.|\!|\?)(?<!Mr\.|Dr\.)(?<!U\.S\.A\.)\s+(?=[A-Z]))) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- (?: group, but do not capture: ---------------------------------------------------------------------- (?<= look behind to see if there is: ---------------------------------------------------------------------- \. '.' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- \! '!' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- \? '?' ---------------------------------------------------------------------- ) end of look-behind ---------------------------------------------------------------------- (?<! look behind to see if there is not: ---------------------------------------------------------------------- Mr 'Mr' ---------------------------------------------------------------------- \. '.' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- Dr 'Dr' ---------------------------------------------------------------------- \. '.' ---------------------------------------------------------------------- ) end of look-behind ---------------------------------------------------------------------- (?<! look behind to see if there is not: ---------------------------------------------------------------------- U 'U' ---------------------------------------------------------------------- \. '.' ---------------------------------------------------------------------- S 'S' ---------------------------------------------------------------------- \. '.' ---------------------------------------------------------------------- A 'A' ---------------------------------------------------------------------- \. '.' ---------------------------------------------------------------------- ) end of look-behind ---------------------------------------------------------------------- \s+ whitespace (\n, \r, \t, \f, and " ") (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- (?= look ahead to see if there is: ---------------------------------------------------------------------- [A-Z] any character of: 'A' to 'Z' ---------------------------------------------------------------------- ) end of look-ahead ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

Replies are listed 'Best First'.
Re^2: Help Me Understand This Regex
by sanju87 (Initiate) on Apr 07, 2012 at 08:12 UTC
    Thank you...cannot be explained better.. Thanks !!