使用正则表达式查找 'part' 个单词

Finding a 'part' word with RegEx

我想找章节,找句子中的单词。

sentence1 = 'chapter1'
sentence2 = 'chapter 1'
sentence3 = 'part1'
sentence4 = 'part 1'
sentence5 = 'party'

re.search('((\bchapter\b|\bpart$\b)|[ ^a-z*,0-9]+)+', sentence5)

但我不想得到像'part(y)'这样的词。我的意思是代码应该找到前 4 个句子,但不应该找到第 5 个句子。

$ 是行尾,不是字边界。

^((\bchapter)|(\bpart))\s?[0-9]