Quirksmode has a “Browser Detection” Script that you can use to detect the various browsers that are used, and then perform various actions based on this type of browser.
Under the hood, essentially the same method you are trying to use is used.
. - == != voila, script !
Chrome, Safari! , :
"Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.10
(KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10"
UserAgent String "Safari", , script , Safari!