Ruq, to use the grep, first set the preferences using
Then
myText.changeGrep() or myText.findGrep().
both methods return an array of found texts, so if you need to manipulate those results remeber the cardinal rule of ALWAYS ITERATING THE ARRAY BACKWARDS, otherwise you might invalidate references to the found objects.
@Dave:
Your getTable function has one problem. What if the selection is a story, or just a text, containing a table.