I am trying to extract a selected number of words surrounding a given word. I will give example to make it clear:

*string = "Education shall be directed to the full development of the human personality and to the strengthening of respect for human rights and fundamental freedoms."*

1) The selected word is **development** and I need to get the 6 words surrounding it, and get : [to, the, full, of, the, human]

---

2) But if the selected word is in the beginning or in second position I still need to get 6 words, e.g:

The selected word is **shall** , I should get: [Education, be, directed, to , the , full] 

I should use 're' module. What I managed to find until now is :

```
def search(text,n):
'''Searches for text, and retrieves n words either side of the text, which are retuned seperatly'''
word = r"\W*([\w]+)"
groups = re.search(r'{}\W*{}{}'.format(word*n,'place',word*n), text).groups()
return groups[:n],groups[n:]

```

but it helps me only with the first case. Can someone help me out with this, I will be really grateful. Thank you in advance!