Jump to content

StringRegExp - validate domain tld & cctld


Recommended Posts

Hi everyone.

first of all thank you for all the good forum post - they helped me a lot to start digging into Autoit.

But I am at a point know where I am lost and still can't find the right way to use StringRegExp in my script.

 

How can I validate if a string is a valid tld or cctld (example: domain.com or domain.co.uk

 

1. Element (the name before the dot) has to be only Letters, Number or the minus sign:   [A-Z0-9-]+

2. Element has to be 1 dot:  \.

3. Element the tld can only be letters: [A-Z]+

...that would be for  TLD
 

4. + 5.  Element the cctld  is optional but max once and has to be  "dot followed by only letters" : \.[A-Z]?

 

My best string result so far is:

StringRegExp($domains[$i], "(?i)([A-Z0-9-]+\.[A-Z]{2,10}){1}$")

 

But this see domain.co1.uk as valid which is wrong because  only letters are allowed after the dot

 

Can anyone help me here?

Thanks

Uwe

Link to comment
Share on other sites

  • 1 year later...

I don't want subdomains, for example www. cdn ...
But I want the .co.il domains
Example ِDomains:

Quote

neto.net.il
60israel.org.il
tau.ac.il
weizmann.ac.il
saritlorens.co.il
saribeauty.co.il


Is it possible?

screenshot.png

Link to comment
Share on other sites

#Include <Array.au3>

$txt = "neto.net.il" & @crlf & _ 
    "60israel.org.il" & @crlf & _ 
    "www.tau.ac.il" & @crlf & _ 
    "www.tau.ac.co.uk" & @crlf & _ 
    "weizmann.ac.il" & @crlf & _ 
    "ww2.saritlorens.co.il" & @crlf & _ 
    "saribeauty.co.il"

$ext = "uk" ;"il"
$res = StringRegExp($txt, '(?m)^(?:ww.\.)?(.*?\.' & $ext & ')$', 3)
_ArrayDisplay($res)

:)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...