Eeuw, what a strangely worded rule. It sounds as if you've only got one site. The ordinary form is
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
If different parts of
the same site use either https or http, you may need to go a little fancier. But in general, try to stick with literal text in the target. The (blahblah)? part takes care of your first condition, so it's "exactly my preferred form or exactly nothing". Then if you get a wonky request with appended port number, that's taken care of too.
If both forms of your hostname are on Webmaster Tools, you should be able to look up each form's links separately.
Unless they've gone and changed something. You can also check your raw logs for this pattern (assuming ordinary Apache format):
^(\d+\.\d+\.\d+\.\d+) - - \S+ -0[78]00\] "GET (\S+) HTTP/1\.[01]" 30[12].+\n\1 - - \S+ -0[78]00\] "GET \2 HTTP/1\.[01]" 200
Translation: Consecutive requests from the same IP for the same file, where the first receives a redirect. If you've got a busy site this code will need to be tweaked to allow for intervening lines. Further tweaks let you constrain the code to requests for pages. (I did a quick check to make sure there were no typos, and was interested to find that the bingbot loves requesting robots.txt from the "wrong" form of my name.)
If you log headers, you can also look at the hostname that way. But then you have to plow through the unwanted robots; you're probably only interested in the requests that end up with a 200.