There are multiple problems with the code.
The $ symbol means "end", so you can't have one of those in the middle of a RegEx pattern.
The (.*) patterns cause your code to attempt tens of thousands "back off and retry" trial matches per URL request. This is very very slow and inefficient. At least the leading (.*) pattern should be changed to something else.
Finally, URLs for folders and for the index page of a folder should end in a trailing slash. The URL for a page should not have a trailing slash and may or may not have an extension.
IF all the URLs to be redirected have /id/ in them, something like this might work.
RewriteRule ^([^/]+/)+/id/([^/]+/)+([^/.]+)+$ http://www.example.com/$1/id/$2/ [R=301,L]
but I would prefer to strip the final slash
RewriteRule ^([^/]+/)+/id/([^/]+/)+([^/.]+)+$ http://www.example.com/$1/id/$2 [R=301,L]
The code recurses multiple folder levels into $1, then matches /id/, then recurses multiple folder levels into $2, and strips the final part if it does not contain a slash or period.