diff --git a/lib/config/migration.js b/lib/config/migration.js
index b7592e27c9f2c44eda1b562b7bc665b1f50c332f..4d14bac104136422c210ca3cf2c8481568cf564c 100644
--- a/lib/config/migration.js
+++ b/lib/config/migration.js
@@ -235,7 +235,8 @@ function migrateConfig(config) {
         // massage to array first
         const schedules = is.string(val) ? [val] : val;
         // split 'and'
-        for (let i = 0; i < schedules.length; i += 1) {
+        const schedulesLength = schedules.length;
+        for (let i = 0; i < schedulesLength; i += 1) {
           if (
             schedules[i].includes(' and ') &&
             schedules[i].includes('before ') &&
@@ -256,15 +257,15 @@ function migrateConfig(config) {
               const toSplit = schedules[i];
               schedules[i] = toSplit
                 .replace(
-                  /^(after|before) (.*?) and (after|before) (.*?)( |$)(.*)/,
-                  '$1 $2 $6'
+                  /^(.*?)(after|before) (.*?) and (after|before) (.*?)( |$)(.*)/,
+                  '$1$2 $3 $7'
                 )
                 .trim();
               schedules.push(
                 toSplit
                   .replace(
-                    /^(after|before) (.*?) and (after|before) (.*?)( |$)(.*)/,
-                    '$3 $4 $6'
+                    /^(.*?)(after|before) (.*?) and (after|before) (.*?)( |$)(.*)/,
+                    '$1$4 $5 $7'
                   )
                   .trim()
               );