From: Brian Candler Date: 2010-08-28T15:38:51+09:00 Subject: Re: how to detect used protocol (SOAP, JSON, XML etc.) Allan Bonadio wrote: > But of course you can legally stick in spaces so you could use this > regex: > if (datastring..search(/^\s*[\[|\{]/) >= 0) .... Note that even when fixed, that regexp would match [hello] In Ruby you have to use \A to match start of string. Anyway, I'd say this sort of attempted format detection is fairly pointless at best, and dangerous at worst. Better to get the client to tell you explicitly what it has sent. In the case of HTTP, this could be via Content-Type: header or via the URL endpoint, e.g. /foo.xml. In the case of a raw TCP protocol then you can use different port numbers. -- Posted via http://www.ruby-forum.com/.