Following on from Saad's suggestion:
1. To make this a bit more dynamic, instead of the using the two lines to get starttext and endtext from a field on the form, you could assign the 'search for' strings via the JavaScript code.
2. To make the code search for the last part of the first 'search for' string, again, have the string assigned to the starttext variable but change the code from
var start = description.indexOf(starttext)
where starttext is 'example' to
var start = description.indexOf(starttext)
start = start + 1 + starttext.length;
so that it will cope with starttext being 'an'. It just finds the location of the beginning of 'an' (or whatever you want) in the string, adds on 1 (for the space in between the words) and then adds on the length of starttext - this should give you the start
of the string you want to extract.