protected function fixOptionalSlashes($string)
    {
        // split up the string to an array
        $parts = explode('/(', $string);

        // create emtpy output
        $regex = '';

        // count how many params there is
        $num = count($parts);

        // create counter
        $counter = 1;

        // loop through the params
        foreach ($parts as $part) {

            // add the param back to the regex/output
            $regex .= $part;

            // make sure it's not the last param
            if ($num > $counter) {
                // check ahead on next param and determine if its optional or not

                if (preg_match('/\)\?$/', $parts[$counter])) {
                    // next param is optional so make the slash optional as well
                    $regex .= '(/)?(';
                } else {
                    // next param is required and so should the slash be as well
                    $regex .= '/(';
                }
            }

            // increase counter
            $counter++;
        }

        // return regex
        return $regex;
    }