我想在Java中编写一个正则表达式来匹配一系列单词字符和空格,后跟字符序列“子类”的单词字符和空格序列:
应匹配的示例字符串:
a subclass of b
a and b subclass of c
a and b subclass of c and d
不应匹配以下字符串:
subclass of
a subclass of
subclass of b
a subclass of b subclass of c
我尝试了以下正则表达式:
[a-zA-Z0-9 ]+subclass of[a-zA-Z0-9 ]+
(?:(?!subclass of).)+subclass of(?:(?!subclass of).)+
但它们都达不到我的需要。