使用 lookbehind 來測試結尾

可以在圖案的末尾使用 lookbehind 以確保它以某種方式結束或不結束。

([a-z ]+|[A-Z ]+)(?<! ) 僅匹配小寫或僅大寫單詞的序列,同時排除尾隨空格。