Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse URL Address

Status
Not open for further replies.
Why would you use a regular expression for this. Use string functions to do this like .Contains("Foo")
 
Requirement in this case is that the 'Foo' part is dynamic and will never been the same.

DH
 
Hmmn. don't follow you. I will not know what the value is until I parse it from the URL, so a variable will not help in this case.

I need to extract it from the URL at which time I will store it in a variable.

DH
 
You say it is dynamic.. you mean one time you will need to search for "Foo" and the next it may be "Somethingelse"?

You can't grab it till you know what you want to grab.

I am not following you now ..lol
 
I guess the best way to put it that initially the value is unkown. A visitor to the site supplies the value as part of the URL so it will be unkown initially.

I have been working with the following code that is working nicely but needs a little fine tuning:

Code:
Dim domainName As String = "mysite.com"
Dim urlPath As String = "[URL unfurl="true"]http://www.mysite.com/foo"[/URL]
Dim regexPattern As String = String.Format("^https?://(.*?)?\.?{0}/(.*?)?/?$", domainName.Replace(".", "\."))
Dim reMatch As Match = Regex.Match(URL, regexPattern)
Response.write(reMatch.Groups(2))

The above code returns 'foo'

But if the urlPath is "
The code will return 'foo/blah.aspx'

So just need to finish stripping off anything after the / for example '/blah.aspx'

DH
 
You could just use the Split method on the string


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top