Tokaniz strings in textarea

Tokaniz strings in textarea

Hello all,
i need any guidelines how to implement the following :
- I Have a textarea where the user can enter any expression he needs.
- Also have a listbox contains some tokens (token may be 2 or 3 words)
- user can select one token and click insert the those two words will be inserted.
- as this a textarea and the edit is allowed i need to be able to delete token ( 2 words) if the user click backspace to delete and character of this token ==> remove whole token

How can i do so ?