Andrew: I'm pretty sure this is wrong:
The ^ character only means negation when used inside of [ ].
In any case, you forgot the | between \? and \! if you were looking for "or" conditions. And also, in any case, you are missing parens.
But I'm pretty sure that should be
But I think that
would also work. ?! is a *negative* non-capture. The ! is the negation character for captures, not the ^
Did you test it? Against many samples, as I did?
EDIT: I did test it.
I tested both your version:
(I added the missing | before the first \!)
And my modification:
Neither passed all tests.
Neither could find "happy" in aardvarks whistle. happy dogs bark
Neither isolated the sentence in either
aardvarks whistle dixie! happy dogs bark
happy happy happy! and even more happy?
(that is, in both cases they returned the entire test string)
I will say that your (?:^|\.|\?|\!) seemed to have mostly worked. Surprised me.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Last edited by Old Pedant; 01-31-2013 at 10:56 PM..