简体   繁体   中英

Match domain names as regular expressions

can some tell how can i write regular expression matching abc.com.ae or abc.net.af or anything ,ae which is the last in the string is optional

this is successfull with / but not . don't know why

^[a-z]{1,25}.[a-z]{3}$

answer

^[a-z]{1,30}\.[a-z]{3}((\.)[a-z]{2})?$

The answer is: write \\. instead of . , because . means “any character”.

You can match specific characters using the \\u escape code followed immediately by the unicode number for that character in hex format and it must also be four digits only. I think a full stop is \..

In your example where '/' works but not '.', this is because a '/' is recognised as a normal character and does not need to be escaped whereas the full stop has a different meaning in c# regex (it matches any character).

If youre still not sure, here is a useful guide to regex in C#: http://www.radsoftware.com.au/articles/regexlearnsyntax.aspx And this one has examples of regex for URLs: http://www.radsoftware.com.au/articles/regexsyntaxadvanced.aspx

I sounds like you need some environment to learn regular expressions.

The best way to learn regular expressions is with an interactive regular expression simulator: type in an expression, and it will give you the results, instantly.

There are a few free (and not so free) regular expression simulators available:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM