tags:

views:

94

answers:

3
+1  Q: 

regular expression

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})?$
A: 

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 \u002E.

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

rmx
+3  A: 

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

Timwi
A: 

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:

Gravitas