William James wrote:
> gga wrote:
> > I am usually pretty good at regexes but this one has me stumped.
> > I want to basically match any line that has a period in it, but only if
> > that period is not part of a salutation.  Ideally I want to do this
> > with a single regex.
> >
> > Thus:
> > 'end of line. And we continue'    # should match
> > 'The incredible Mrs. Robner'      # should not match
> > 'Sammy Davis Jr. is an okay guy.' # should match, due to last .
> >
> > I tried doing something logical, like:
> >
> > /(?!Jr\.|Sr\.|Miss\.|Mr\.|Mrs\.)\./
> >
> > but, alas, this does not work.  Any ideas?
>
> a = [
>  'end of line. And we continue',
> 'The incredible Mrs. Robner',
> 'Sammy Davis Jr. is an okay guy.'
> ]
>
> a.each {|s|
>   puts s if s.gsub(/(?:Jr\.|Sr\.|Mr\.|Mrs\.)/,"") =~ /\./
> }

This would be a lot easier if Ruby had look-behind.

[
'.start',
'-. HERE .-',
'Jr. is rotten',
'Mr. Smith is here',
'Mr-. Smith is here',
'Mr. Smith is here.',
'Mrs. Jones left',
'Meet Mr. Elihu Snark, Jr.',
'A good line.',
'A mystery guest, introduced by his father, Mr. Bob Eck, Sr.'
].each {|s|
  if s =~ %r{  (?:
                   (?!Jr|Sr|Mr) ^ .{0,2}  |
                   (?!.Jr|.Sr|.Mr|Mrs) ...
               )
               \.
            }x
    puts s
  end
}