我正在处理一个公交系统的大量大写站点名称,并希望将诸如"at“和"the”这样的单词去大写。到目前为止,我可以匹配所有我想要的实例,除了我无法弄清楚如何不匹配在字符串开头出现的实例。(即防止将“事物”改为“事物”)>>>re.sub("(?i)(?<!\w)the(?!\w)", "zzz", "The Thing To The Theme of Athens, (The) Goethe")
'zzz Thing To zzz Theme of Athens, (zzz
我需要替换字符串中的匹配词,但不包括这些词的前缀列表。 The matchingWord should be replaced in the first lineNeither in this other line excludePrefix2.matchingWord
But again in this allowedPrefix.matchingWord 我成功地使用了一个带有单个前缀的正则表达式: (?<!(excludePrefix1\.))matchingWord 但是,如