views:

62

answers:

1

I want to ignore IPad as a mobile device in my application

I'm currently using this expression to detect mobile devices:

request.user_agent =~ /Mobile|webOS/

Standard stuff. The iPad agent string looks something like:

Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B405 Safari/531.21.10

I've tried the following without success:

request.user_agent =~ /!(iPad)(Mobile|webOS)/

Please let me know what is wrong with the expression.

Thank you.

+3  A: 

You can use negative matches or

request.user_agent =~ /Mobile|webOS/ && !(request.user_agent =~ /iPad/)
Simone Carletti
That did it, thank you. I'm new so it won't let me vote it up. I did accept it as the answer. I'd be interested to see this as a single regular expression if possible.
ron