これはあなたが必要なテキストを抽出役立つ可能正規表現である:私はできませんがまた、Pythonの例
(?:[^ ]+){0,10}wolf(?: [^ ]+){0,10}
は、同じように行く必要があります今すぐテストしてください:
import re
t = "The domestic dog (Canis lupus familiaris or Canis familiaris) is a member of genus Canis (canines) that forms part of the wolf-like canids, and is the most widely abundant carnivore. The dog and the extant gray wolf are sister taxa, with modern wolves not closely related to the wolves that were first domesticated, which implies that the direct ancestor of the dog is extinct. The dog was the first domesticated species and has been selectively bred over millennia for various behaviors, sensory capabilities, and physical attributes"
m = re.search("(?:[^ ]+){0,10}wolf\s(?:[^ ]+){0,10}", t)
if m:
print (m.group(0))
これは簡単ですが、あなたはgです大量のテキストを使用してパフォーマンスの問題に遭遇する可能性があります。 – WombatPM