0

I am new to Regular Expression and I have this pattern below in my VBscript function for validating the email address.

regEx.Pattern ="^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,4}$"

1) Would someone please explain this pattern in words how this works? What is the dash (-) behind does? like w-, Z-

^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,4}$

2) Also, looks like it only return TRUE if the top-level domain is 2 to 3 characters (like .com, .edu). How can I change to unlimited top-level domain after the dot (.)? For examples: test1@domain1.career, test2@domain2.consulting

Thanks min advance,

Milacay
  • 1,407
  • 7
  • 32
  • 56
  • 1
    Possible duplicate of [Reference - What does this regex mean?](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – revo Sep 18 '17 at 17:52
  • 2
    Copy/paste it into [regex101](https://regex101.com), it'll explain your regex. But basically: 1 or more word character, `-` or `.` followed by `@`, { then by 1 or more of the following set `[ digit, character from a-z or A-Z, or - ]` followed by a dot } (repeated between 1 and unlimited times), followed by 2 to 4 characters from the following set `[ digit, character from a-z or A-Z, or -]`. This regex uses `^` to assert the beginning of the string as the starting position and `$` to assert the ending of the string as the ending position. – ctwheels Sep 18 '17 at 18:01
  • 1
    @Milacay you're very welcome. You should look at other regexes for email parsing, however, since this doesn't necessarily conform to RFC email standards (and no regex will be 100% able to do so due to the nature of email formatting). Your best bet for checking the validity of an email is to send a test email to it and see if you get a response. – ctwheels Sep 18 '17 at 18:09
  • @ctwheels thanks again for taking time to explain. – Milacay Sep 18 '17 at 20:59

1 Answers1

0
 ^   =   String starts with



\w  =   Ranges: matches a letter between A to B,a to b and figures from 1  to 9

 \.  =  matches character (.)

{1,} =  Occur one or more times

\@   =  matches character (@)

[\da-zA-Z-] = match a single character between digit 0-9,a-z , A-Z and -

{2,4} =  Occur 2 to 4 times

^[\w-\.]{1,} indicate abc9-. or 9ab-.

[\da-zA-Z-]{2,4} indicates 1ab or ab- or ab3-

to change unlimited top-level domain after the dot (.) change Regular Expression 

^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{1,}$

output will be: test1@domain1.career
user9862376
  • 29
  • 10