一个正则表达式,在Apache上工作正常,但在nginx上失败

I have a following regex expression which works well in apache but doesn't in nginx.

 preg_replace("/(src=\")(.*)([^>]*)(".$base_url_mod."\/)/",
  "data-$1$2$3", $content);

If I remove (".$base_url_mod."\/)/ it started to work but that's not what I want.

Full function:

function tt_type_filter ( $content ) {
    $post_type = get_post_type();

    if($post_type == 'page' || $post_type == 'post') {
        $tt_connector = get_option ( 'tt_connector' );
        $base_url = get_site_url();

        $base_url_arr = parse_url($base_url);
        $base_url_mod = $base_url_arr[scheme]. '\:\/\/' .$base_url_arr[host]. '\\' .$base_url_arr[path];

        if($tt_connector == $base_url) 
            return preg_replace("/(src=\")(.*)([^>]*)(".$base_url_mod."\/)/", "data-$1$2$3", $content);
        else 
            return preg_replace("/(src=\")(.*)([^>]*)(uploads\/)/", "data-$1$3", $content);
    }
}

Eg.(Purpose of this expression)

http://wp.mysite.net/wp4/wp-content/uploads/2012/10/someimage.jpg should be replaced with http://api.mydomain.com/images/domain/2012/10/someimage.jpg

I have managed to fix it at my own.

The issue was with $base_url_mod. It was adding \/ at the end of the path when $base_url_arr[path]having empty/no value. So I'd to put a condition in the function and it started to work.

Here is an updated function: (works fine on both, apache and nginx)

function tt_type_filter ( $content ) {
    $post_type = get_post_type();

    if($post_type == 'page' || $post_type == 'post') {
        $tt_connector = get_option ( 'tt_connector' );
        $base_url = get_site_url();

        $base_url_arr = parse_url($base_url);
        if ($base_url_arr[path]) {
            $base_url_mod = $base_url_arr[scheme]. '\:\/\/' .$base_url_arr[host]. '\\' .$base_url_arr[path];
        } else {
            $base_url_mod = $base_url_arr[scheme]. '\:\/\/' .$base_url_arr[host];
        }

        if($tt_connector == $base_url)
            return preg_replace("/(src=\")(.*)([^>]*)(".$base_url_mod."\/)/", "data-$1$2$3", $content);
        else
            return preg_replace("/(src=\")(.*)([^>]*)(uploads\/)/", "data-$1$3", $content);
    }
}