--- a/filefield_paths.module	Sun Jun 09 23:30:59 2013
+++ b/filefield_paths.module	Mon Nov 25 05:51:46 2013
@@ -306,32 +306,37 @@
   $absolute = str_replace("{$info['host']}{$info['path']}", '', file_create_url($old));
   $relative = parse_url($absolute, PHP_URL_PATH);
   $regex = str_replace('/', '\/', "({$absolute}|{$relative}|{$info['scheme']}://)(styles/([a-z0-9\-_/]*?)/{$info['scheme']}/|)({$info['host']}{$info['path']})");
 
   // Build replacement.
   $info = parse_url(file_stream_wrapper_uri_normalize($new));
   $info['path'] = !empty($info['path']) ? $info['path'] : '';
-  $replacement = "_filefield_paths_replace_path_uri_scheme('\\1', '{$old}', '{$new}') . '\\2{$info['host']}{$info['path']}'";
-
+  $replacement = function($m) use($old,$new,$info){
+	$result = _filefield_paths_replace_path_uri_scheme($m[1], $old, $new) . $m[2] . $info['host'] . $info['path'];
+	if(defined('IMAGE_DERIVATIVE_TOKEN')){
+		$result .= _filefield_paths_replace_image_derivative_token($old, $new, $m[5], $m[7], $m[3]);
+	}
+	return $result;
+  };
+  
   // Newer versions of the Image module add an 8 character token which is
   // required if the image style hasn't been generated yet. Look for this token
   // in the query string and replace it.
   if (defined('IMAGE_DERIVATIVE_TOKEN')) {
     $regex .= '(\?(\S+?&|)' . IMAGE_DERIVATIVE_TOKEN . '=(\S{8})|)';
-    $replacement .= " . _filefield_paths_replace_image_derivative_token('{$old}', '{$new}', '\\5', '\\7', '\\3')";
   }
 
   $fields = field_info_fields();
   foreach ($fields as $name => $field) {
     if ($field['module'] == 'text' && isset($entity->{$field['field_name']}) && is_array($entity->{$field['field_name']})) {
       foreach ($entity->{$field['field_name']} as &$language) {
         foreach ($language as &$item) {
-          $item['value'] = preg_replace("/$regex/e", $replacement, $item['value']);
+          $item['value'] = preg_replace_callback("/$regex/", $replacement, $item['value']);
           if (isset($item['summary'])) {
-            $item['summary'] = preg_replace("/$regex/e", $replacement, $item['summary']);
+            $item['summary'] = preg_replace_callback("/$regex/", $replacement, $item['summary']);
           }
         }
       }
     }
   }
 }
 
