4 replies
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.
#regex
  • Profile picture of the author pbarnhart
    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
    {{ DiscussionBoard.errors[2384246].message }}
    • Profile picture of the author nmarley
      Originally Posted by webfighter

      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 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?
      {{ DiscussionBoard.errors[2384715].message }}
  • Profile picture of the author MemberWing
    Originally Posted by webfighter View Post

    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.
    Here it goes:
    http://pastebin.com/TMz817ix

    Gleb
    {{ DiscussionBoard.errors[2384905].message }}
  • Profile picture of the author webfighter
    Thanks Gleb, thats exactly what I wanted Funny, I couldn't think that way myself.
    {{ DiscussionBoard.errors[2385262].message }}

Trending Topics