I posted a similar question earlier, but I now realize I should have been more thorough.
I've tested a number of the URL/URI expressions listed on regexlib.com, but I can't get any of them to work as desired:
msn.com msn-msn.net yahoo.c!om http://www.yahoo.com msn msn test ! number 1
Here is how I desire them to act:
msn.com (match) msn-msn.net (match) yahoo.c!om (fail) http://www.yahoo.com (match) msn msn (fail) test ! number 1 (fail)
I'm using the tester here: http://regexlib.com/RETester.aspx before testing in my own app (C#, .NET 4.0)
The expression that is closest is this, but it doesn't match the http://www.yahoo.com one:
Any help is appreciated. Additionally, somebody should come up with a more human-readable equivalent to RegEx...this stuff is a nightmare.
If you can't guarantee that the URL-esque pattern you're trying to match has a scheme/protocol, then the safest thing to do is match against top-level domains:
From your post it's evidently not necessary to go into the path, hash, or querystring parts of a URL, so that's it!
This one appears to work as desired:
Can anyone see any issues with this in regards to my original query? I don't need to validate whether the TLD is proper, so this isn't really an issue.
Agree with kojiro
But this does match your tests