/ ( .+? # match (non-greedy) anything ... [.!?] # ... followed by any one of !?. [")]? # ... and optionally " or ) ) (?= # with lookahead that it is followed by ... (?: # either ... \s+ # some whitespace ... ["(]? # maybe a " or ( ... [A-Z] # and capital letter | # or ... \s*$ # optional whitespace, followed by end of string ) ) /gx ;