You can use the regex module reand the function sub(replace / replace) in combination with lookahead (?=from)and lookbehind (?<=copy )- also called lookaround , to remove only the requested part (.*)that is between them:
import re
print re.sub(r'(?<=copy )(.*)(?=from)', '', "copy table values from 'a.dat';")
OUTPUT
copy from 'a.dat';
source
share