From: William James Date: 2006-12-26T07:10:06+09:00 Subject: Re: Searching Stings with Arrays? Phil Cooperking wrote: > Tom Werner wrote: > > Phil Cooperking wrote: > >> > >> > > This might get you started off on the right path: > > > > m, agent = *@string.match(/(shiira|msie|safari|firefox|netscape)/) > > p agent > > > > outputs > > > > safari > > > > If you need further clarification of this code, just let me know. > > > > Tom Werner > > can I tag a regex on to this to pull the version of the browser? I > understand I might have to to break this down as some useragents are > differently setup. @string = "mozilla/5.0 (macintosh; u; ppc mac os x; en) applewebkit/418.9.1 (khtml, like gecko) safari/419.3" array = ["shiira", "msie", "safari", "firefox", "netscape"] @string =~ %r{(#{ array.map{|s| Regexp.escape(s)}.join('|')})/(\S+)} p $1,$2 browser,version = @string.match( %r{(#{ array.map{|s| Regexp.escape(s)}.join('|')})/(\S+)}). captures p browser,version