diff --git a/support/tools/MoM/process_mom_sql.py b/support/tools/MoM/process_mom_sql.py
index b138c92a845ea3288996468325be25c4ce936a10..cb186438d8c258edb0f36ecb9f9d9614dd3b62bf 100755
--- a/support/tools/MoM/process_mom_sql.py
+++ b/support/tools/MoM/process_mom_sql.py
@@ -117,11 +117,14 @@ with open(infile) as f:
             possible_trigger = False
             filename = line.translate(None, '/*;`!@=\n()').replace(' ','_')
             if 'DROP_TABLE_IF_EXISTS_' in filename:
-                filename = 'CREATE_TABLE_OR_VIEW_' + filename[filename.find('DROP_TABLE_IF_EXISTS_') + 21:]
+                filename = 'CREATE_TABLE_OR_VIEW_' + \
+                           filename[filename.find('DROP_TABLE_IF_EXISTS_') 
+                           + len('DROP_TABLE_IF_EXISTS_'):]
             if 'LOCK_TABLES_' in filename:
-                filename = 'WRITE_TABLE_' + filename[12:-6]
+                filename = 'WRITE_TABLE_' + filename[len('WRITE_TABLE_'):-len('WRITE;')]
             if 'TRIGGER' in line:
-                filename = 'CREATE_' + filename[filename.find('TRIGGER'):-19]
+                filename = 'CREATE_' + \
+                           filename[filename.find('TRIGGER'):-len('_FOR_EACH_ROW_BEGIN')]
             outfile = open(outdir + "%06d_" % line_nr + filename + ".sql", 'w')
             outfile.write(buffer)
             buffer = ""