DickSwart
asked on
Help with regular expression
Hi All,
I'm having trouble with regular expressions, can anyone please help.
I'm trying to convert a string into a regular expressions, but my expression is to broad and I need to narrow it down.
if I get a string "*.domain.co.za/*" I'm converting it to a regular expresson as such:
the thing is this is far to broad how can I change the expression to validate to the following:
With these rules applied I think only the following will pass:
http://www.domain.co.za
http://www.domain.co.za/something/somethin
http://sub1.domain.co.za
http://sub2.domain.co.za/something/somethin
Is it possible to also allow http://domain.co.za to pass.
The following should not pass:
ftp://www.domain.co.za
http://www.asdg.domain.co.za
http://www.otherDomain.co.za
If it is possible please explain the expression.
I'm having trouble with regular expressions, can anyone please help.
I'm trying to convert a string into a regular expressions, but my expression is to broad and I need to narrow it down.
if I get a string "*.domain.co.za/*" I'm converting it to a regular expresson as such:
var expressionList = new List<Regex>();
var myString = "*.domain.co.za/*";
if (myString.IndexOf('*') >= 0)
{
expressionList.Add(new Regex(myString.Replace("*.", ".*\\.").Replace("/*", "/.*")));
}
the thing is this is far to broad how can I change the expression to validate to the following:
1.
Must start with http or https followed by ://2.
Any number of char or numbers (no periods ".")3.
myString (.domain.co.za/)4.
anything elseWith these rules applied I think only the following will pass:
http://www.domain.co.za
http://www.domain.co.za/something/somethin
http://sub1.domain.co.za
http://sub2.domain.co.za/something/somethin
Is it possible to also allow http://domain.co.za to pass.
The following should not pass:
ftp://www.domain.co.za
http://www.asdg.domain.co.za
http://www.otherDomain.co.za
If it is possible please explain the expression.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.