Regex help please?

by 4 replies
6
Hello,

I'm trying to match a specific type of email address.

What I want is that the email address either ends with the tld "in" or "info".

This is what I've so far:

Code:
[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+.(in|info)
But the way it works, it matches only upto "webfighter@wf.in" if the email address is "webfighter@wf.info".

Also, I cannot use the $ sign to match the end of string because the email addresses are comma separated and can even have some weird characters at the end of them.

I'm quite new to regex and any help will be highly appreciated.

Thank you.
#programming #regex
  • There is an excellent discussion of this at How to Find or Validate an Email Address

    Essentially, the recommended solution is:

    Code:
    ^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$
    There are some tradeoffs - as discussed in the article. I have used this for years without much problem.

    To learn more about regex, you should check out Learn Regular Expressions by Example
    • [ 1 ] Thanks
    • [1] reply
    • I recommend you split those up first. Seriously, it will make this a lot easier for you if you split them into an array and loop through it to process them.

      What programming language are you using?
      • [ 1 ] Thanks
  • Here it goes:
    http://pastebin.com/TMz817ix

    Gleb
    • [ 1 ] Thanks
  • Thanks Gleb, thats exactly what I wanted Funny, I couldn't think that way myself.

Next Topics on Trending Feed