If you just need to distinguish between text-only and graphical browsers, you're in good shape. Let's face it: There's just one text-only browser with enough users to bother going out of your way for: Lynx. And its User Agent string always starts with "Lynx," so it's easy to identify.
If you simply need to distinguish between the big two - Netscape and IE - notice that Netscape's product name is Mozilla.
Unfortunately, IE also starts its User Agent string with Mozilla. Lots of browsers pretend to be Mozilla compatible, presumably because sneaky Web programmers like us used to just look for the string Mozilla as we checked for the availability of certain features. To find IE, you should look for the string MSIE in one of the parenthesized comments.
So you could assume that any browser whose User Agent string starts with Mozilla is Netscape, unless you find MSIE in one of the comments, in which case you've got an IE user on your hands. You could check for Opera this way as well, since as you can see above, Opera always identifies itself somewhere inside the parentheses.
If you want the version information, know that it's almost always separated from the name of the browser by a slash or by a single space.
To find platform info, as with browser info, you pretty much have to know what you're looking for. There's no guarantee about which comment within the parentheses contains the platform info, so it's a good idea to check each of them against a predictable list of strings, such as X11, SunOS, Linux, Mac, PPC, Win, and anything else you want to check.
So to recap, here's a high-level, pseudo algorithm for parsing the User Agent string:
Parse the stuff before the left parenthesis (if there is one) and look for browser and version info. (If it's Mozilla, you might change your mind later.)
Loop through each of the semicolon-separated tokens within the parentheses and check each one against:
a fixed list of strings to see if the token contains the real browser and version info
and a fixed list of strings to find possible platform info.
Here's a sample JavaScript implementation of the algorithm described above. A huge number of sites appear to be doing their browser detection with client-side JavaScript, even though one of the things you might want to detect is whether or not the client is JavaScript enabled.
Another reason this example is slightly contrived is that of course the client already knows which browser it's dealing with; the client doesn't have to go looking into the User Agent string that it sends to a server. So in JavaScript, you can also use the navigator.appName and navigator.appVersion properties, which theoretically might not coincide with the information that's in the User Agent string. But our example is more portable and is intended to illustrate the general principles we've already discussed.