Monday, November 16, 2009

URL Regular Expression Pattern

Tonight I search for a regex pattern to parsing ftp or http url. I found some but I choose Ivan's pattern and then I modify it to suit my problem. this is the result.

^(ht|f)tps?:(//)(w+(:w+)?@)?([-w]+.?)*[-w]+(:[d]{1,5})?(/([-w~!$+|.,=]|%[a-fd]{2})+)*(/)?(?([-w~!$+|.,*:]|%[a-fd{2}])+=?([-w~!$+|.,*:=]|%[a-fd]{2})*(&([-w~!$+|.,*:]|%[a-fd{2}])+=?([-w~!$+|.,*:=]|%[a-fd]{2})*)*)?(#([-w~!$+|.,*:=]|%[a-fd]{2})*)?$

Some paths derive from Ivan's pattern and some I rewrite it. I note this for further use in the future. Hope it maybe useful to you too.
And I also found regexpal which is a great online regex tool.

No comments:

Post a Comment