I am using Rails 3.1.1 and I would like to recognize (maybe using a regex) if a string “contains”/”is”/”represents” one of the following:
- an email address
- a Web site URL
- a number
I am trying to implement a method that, given a string, returns:
emailif the string is something likemy_nick@email_provider.orgwebsiteif the string is something likewww.web_address.orgnumberif the string is something like123nullotherwise
Is it possible? How can I make that?
Here’s some code for you:
You can look up individual regexes for each case above — or perhaps you can find non-regex solutions for some cases.