I saw many questions and answers and I can not gave a good answer.
I saw that some people did not follow the rules of domain registration like (You can not use '-' more than once in a row in domain name but you can use it many time. For instance: www.my--domain-name.com is false and www.my-domain-name.com is true.
For example I saw this link What is a good regular expression to match a URL? but it has some problems.
I used this code (https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})
but I can not resolve my problem
I used this regular expression in asp.net and it is working so good for me:
^[(((ftp|http|https):\/\/)?(?:www\.|(?!www))[\u0061-\u007a\u0041-\u005a\u0030-\u0039 \u2000-\u200f\u2028-\u202f\u0621-\u0628\u062a-\u063a\u0641-\u0642\u0644-\u0648\u064e-\u0651\u0655\u067e\u0686\u0698\u06a9\u06af\u06be\u06cc\u06f0-\u06f9\u0629\u0643\u0649-\u064b\u064d\u06d5\u0660-\u0669\u005c]+(-[\u0061-\u007a\u0041-\u005a\u0030-\u0039 \u2000-\u200f\u2028-\u202f\u0621-\u0628\u062a-\u063a\u0641-\u0642\u0644-\u0648\u064e-\u0651\u0655\u067e\u0686\u0698\u06a9\u06af\u06be\u06cc\u06f0-\u06f9\u0629\u0643\u0649-\u064b\u064d\u06d5\u0660-\u0669\u005c]+)*\.[^\s^_]{2,}|www\.[\u0061-\u007a\u0041-\u005a\u0030-\u0039 \u2000-\u200f\u2028-\u202f\u0621-\u0628\u062a-\u063a\u0641-\u0642\u0644-\u0648\u064e-\u0651\u0655\u067e\u0686\u0698\u06a9\u06af\u06be\u06cc\u06f0-\u06f9\u0629\u0643\u0649-\u064b\u064d\u06d5\u0660-\u0669\u005c]+(-[\u0061-\u007a\u0041-\u005a\u0030-\u0039 \u2000-\u200f\u2028-\u202f\u0621-\u0628\u062a-\u063a\u0641-\u0642\u0644-\u0648\u064e-\u0651\u0655\u067e\u0686\u0698\u06a9\u06af\u06be\u06cc\u06f0-\u06f9\u0629\u0643\u0649-\u064b\u064d\u06d5\u0660-\u0669\u005c]+)*\.[^\s^_]{2,}|((ftp|http|https):\/\/)?(?:www\.|(?!www))[\u0061-\u007a\u0041-\u005a\u0030-\u0039 \u2000-\u200f\u2028-\u202f\u0621-\u0628\u062a-\u063a\u0641-\u0642\u0644-\u0648\u064e-\u0651\u0655\u067e\u0686\u0698\u06a9\u06af\u06be\u06cc\u06f0-\u06f9\u0629\u0643\u0649-\u064b\u064d\u06d5\u0660-\u0669\u005c]+(-[\u0061-\u007a\u0041-\u005a\u0030-\u0039 \u2000-\u200f\u2028-\u202f\u0621-\u0628\u062a-\u063a\u0641-\u0642\u0644-\u0648\u064e-\u0651\u0655\u067e\u0686\u0698\u06a9\u06af\u06be\u06cc\u06f0-\u06f9\u0629\u0643\u0649-\u064b\u064d\u06d5\u0660-\u0669\u005c]+)*\.[^\s^_]{2,}|www\.[\u0061-\u007a\u0041-\u005a\u0030-\u0039 \u2000-\u200f\u2028-\u202f\u0621-\u0628\u062a-\u063a\u0641-\u0642\u0644-\u0648\u064e-\u0651\u0655\u067e\u0686\u0698\u06a9\u06af\u06be\u06cc\u06f0-\u06f9\u0629\u0643\u0649-\u064b\u064d\u06d5\u0660-\u0669\u005c]+(-[\u0061-\u007a\u0041-\u005a\u0030-\u0039 \u2000-\u200f\u2028-\u202f\u0621-\u0628\u062a-\u063a\u0641-\u0642\u0644-\u0648\u064e-\u0651\u0655\u067e\u0686\u0698\u06a9\u06af\u06be\u06cc\u06f0-\u06f9\u0629\u0643\u0649-\u064b\u064d\u06d5\u0660-\u0669\u005c]+)*\.[^\s^_]{2,}]{1,2083}$
Of course my regular expression has specialized for Persian language and if you want to use it for English language you must use this:
^[(((ftp|http|https):\/\/)?(?:www\.|(?!www))[\u0061\u002d\u007a\u0041\u002d\u005a\u0030\u002d\u0039]+(-[\u0061\u002d\u007a\u0041\u002d\u005a\u0030\u002d\u0039]+)*\.[^\s^_]{2,}|www\.[\u0061\u002d\u007a\u0041\u002d\u005a\u0030\u002d\u0039]+(-[\u0061\u002d\u007a\u0041\u002d\u005a\u0030\u002d\u0039]+)*\.[^\s^_]{2,}|((ftp|http|https):\/\/)?(?:www\.|(?!www))[\u0061\u002d\u007a\u0041\u002d\u005a\u0030\u002d\u0039]+(-[\u0061\u002d\u007a\u0041\u002d\u005a\u0030\u002d\u0039]+)*\.[^\s^_]{2,}|www\.[\u0061\u002d\u007a\u0041\u002d\u005a\u0030\u002d\u0039]+(-[\u0061\u002d\u007a\u0041\u002d\u005a\u0030\u002d\u0039]+)*\.[^\s^_]{2,}]{1,2083}$