467,145 Members | 960 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,145 developers. It's quick & easy.

Regular expression question?

My web application allow the user to enter the site by typing in a subdomain
such as 'name.domain.com'. However, I want to retrieve just the 'name' part
of the subdomain. see code below (the equal sign '=' respresent the value
I'm getting when I run the code)

Test 1.........................name.domain.com
Dim sdmlink As String = Request.Url.ToString

Dim sdm As Regex

sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")

Context.Items("Test") = (sdm.Replace(sdmlink, "$1")) ---->> =
http://name.doman.com/welcome.aspx ---- this should = name

Test 2................name.domain.com
Dim sdmlink As String = Request.Url.ToString

Dim sdm As Regex

sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")

Context.Items("Test") = (sdm.Replace(sdmlink,
"test/default.aspx?Id=$1")) ---->> = test/default.aspx?Id=name ---- this is
correct


Nov 19 '05 #1
  • viewed: 1188
Share:
8 Replies
I think you are realy strugling with this. Its best to keep it to the same
post and not post each question seperatly.

Context.Items("Test") = (sdm.Replace(sdmlink, "$1")) ---->> = http://name.doman.com/welcome.aspx ---- this should = name

You've got a spelling mistake :

name.domAn.com should be name.domAIn.com
^ ^^

if its domAIn the result is correct : name

Let me know if you have any more questions..

Cheers,
Tom Pester
My web application allow the user to enter the site by typing in a
subdomain such as 'name.domain.com'. However, I want to retrieve just
the 'name' part of the subdomain. see code below (the equal sign '='
respresent the value I'm getting when I run the code)

Test 1.........................name.domain.com
Dim sdmlink As String = Request.Url.ToString
Dim sdm As Regex

sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")

Context.Items("Test") = (sdm.Replace(sdmlink, "$1")) ---->> =
http://name.doman.com/welcome.aspx ---- this should = name

Test 2................name.domain.com
Dim sdmlink As String = Request.Url.ToString
Dim sdm As Regex

sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")

Context.Items("Test") = (sdm.Replace(sdmlink,
"test/default.aspx?Id=$1")) ---->> = test/default.aspx?Id=name ----
this is correct

Nov 19 '05 #2
Yes, I'm struggling, but....
No it's not the spelling. I think the regex expression is not recognizing
the url. what do you think?
I ready do appreciate all the help. Thanks
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)

' Fires at the beginning of each request

Dim sdmurl As String = Request.Url.ToString

Dim sdm As Regex

sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")

Context.Items("Test") = (sdm.Replace(sdmurl, "/welcome.aspx?Id=$1"))

End Sub
<to********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om...
I think you are realy strugling with this. Its best to keep it to the same
post and not post each question seperatly.

Context.Items("Test") = (sdm.Replace(sdmlink, "$1")) ---->> =
http://name.doman.com/welcome.aspx

---- this should = name

You've got a spelling mistake :
name.domAn.com should be name.domAIn.com ^
^^

if its domAIn the result is correct : name

Let me know if you have any more questions..

Cheers,
Tom Pester
My web application allow the user to enter the site by typing in a
subdomain such as 'name.domain.com'. However, I want to retrieve just
the 'name' part of the subdomain. see code below (the equal sign '='
respresent the value I'm getting when I run the code)

Test 1.........................name.domain.com
Dim sdmlink As String = Request.Url.ToString
Dim sdm As Regex

sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")

Context.Items("Test") = (sdm.Replace(sdmlink, "$1")) ---->> =
http://name.doman.com/welcome.aspx ---- this should = name

Test 2................name.domain.com
Dim sdmlink As String = Request.Url.ToString
Dim sdm As Regex

sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")

Context.Items("Test") = (sdm.Replace(sdmlink,
"test/default.aspx?Id=$1")) ---->> = test/default.aspx?Id=name ----
this is correct


Nov 19 '05 #3
Hi Leon,

I ran the code below and added the ouput as comments

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink, "test/default.aspx?Id=$1")
& "<BR>")
' result : test/default.aspx?Id=name

The regex correctly extracts "name" and the code produces "test/default.aspx?Id=name".
This is what you want no?

I think you are tring to say that there are certain inputs that dont give
the correct result. Otherwise I dont understand your problem.

The input above is

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"

What kind of inputs dont work for you?
Cheers,
Tom Pester
Yes, I'm struggling, but....
No it's not the spelling. I think the regex expression is not
recognizing
the url. what do you think?
I ready do appreciate all the help. Thanks
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
' Fires at the beginning of each request

Dim sdmurl As String = Request.Url.ToString

Dim sdm As Regex

sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")

Context.Items("Test") = (sdm.Replace(sdmurl, "/welcome.aspx?Id=$1"))

End Sub

<to********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om...
I think you are realy strugling with this. Its best to keep it to the
same post and not post each question seperatly.
Context.Items("Test") = (sdm.Replace(sdmlink, "$1")) ---->> =
http://name.doman.com/welcome.aspx

---- this should = name

You've got a spelling mistake :
name.domAn.com should be name.domAIn.com ^
^^
if its domAIn the result is correct : name

Let me know if you have any more questions..

Cheers,
Tom Pester
My web application allow the user to enter the site by typing in a
subdomain such as 'name.domain.com'. However, I want to retrieve
just the 'name' part of the subdomain. see code below (the equal
sign '=' respresent the value I'm getting when I run the code)

Test 1.........................name.domain.com
Dim sdmlink As String = Request.Url.ToString
Dim sdm As Regex
sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")

Context.Items("Test") = (sdm.Replace(sdmlink, "$1")) ---->> =
http://name.doman.com/welcome.aspx ---- this should = name

Test 2................name.domain.com
Dim sdmlink As String = Request.Url.ToString
Dim sdm As Regex
sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")

Context.Items("Test") = (sdm.Replace(sdmlink,
"test/default.aspx?Id=$1")) ---->> = test/default.aspx?Id=name ----
this is correct

Nov 19 '05 #4
What kind of inputs don't work for you?
---> you hit the correct input on the head
http://name.domain.com/welcome.aspx -or- http://name.domain.com/

result : test/default.aspx?Id=name
The regex correctly extracts "name" and the code produces
"test/default.aspx?Id=name".
---> perfect that is the exact results I'm looking for almost, but..

This is what you want no?
--->how do I extract just 'name' -not- 'test/default.aspx?Id=name'

Thanks alot tom!

<to********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om...
Hi Leon,

I ran the code below and added the ouput as comments

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink,
"test/default.aspx?Id=$1") & "<BR>")
' result : test/default.aspx?Id=name

The regex correctly extracts "name" and the code produces
"test/default.aspx?Id=name". This is what you want no?

I think you are tring to say that there are certain inputs that dont give
the correct result. Otherwise I dont understand your problem.

The input above is
Dim sdmlink As String = "http://name.domain.com/welcome.aspx"

What kind of inputs dont work for you?
Cheers,
Tom Pester
Yes, I'm struggling, but....
No it's not the spelling. I think the regex expression is not
recognizing
the url. what do you think?
I ready do appreciate all the help. Thanks
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
' Fires at the beginning of each request

Dim sdmurl As String = Request.Url.ToString

Dim sdm As Regex

sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")

Context.Items("Test") = (sdm.Replace(sdmurl, "/welcome.aspx?Id=$1"))

End Sub

<to********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om...
I think you are realy strugling with this. Its best to keep it to the
same post and not post each question seperatly.

Context.Items("Test") = (sdm.Replace(sdmlink, "$1")) ---->> =
http://name.doman.com/welcome.aspx

---- this should = name

You've got a spelling mistake :
name.domAn.com should be name.domAIn.com ^
^^
if its domAIn the result is correct : name

Let me know if you have any more questions..

Cheers,
Tom Pester
My web application allow the user to enter the site by typing in a
subdomain such as 'name.domain.com'. However, I want to retrieve
just the 'name' part of the subdomain. see code below (the equal
sign '=' respresent the value I'm getting when I run the code)

Test 1.........................name.domain.com
Dim sdmlink As String = Request.Url.ToString
Dim sdm As Regex
sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")

Context.Items("Test") = (sdm.Replace(sdmlink, "$1")) ---->> =
http://name.doman.com/welcome.aspx ---- this should = name

Test 2................name.domain.com
Dim sdmlink As String = Request.Url.ToString
Dim sdm As Regex
sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")

Context.Items("Test") = (sdm.Replace(sdmlink,
"test/default.aspx?Id=$1")) ---->> = test/default.aspx?Id=name ----
this is correct


Nov 19 '05 #5
> --->how do I extract just 'name' -not- 'test/default.aspx?Id=name'

Strange that you ask this because you yourself add it in the code :

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink, "test/default.aspx?Id=$1")
& "<BR>")
' result : test/default.aspx?Id=name

your replace with : "test/default.aspx?Id=$1"

if you just want "name" do this :

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink, "$1") & "<BR>") '
' result : name

But we already posted this.

I cleaner way to get the "name" is like this :

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write(sdm.Match(sdmlink).Groups(1))
' result : name

This produces only "name"

I added you to my msn cause I think your english isnt conversation quality
(no offence :)
If you still can't continue lets have a chat
Nov 19 '05 #6
oh I see the problem, but don't know exactly how to fix it...see below

the follow code runs perfect when you pre include the url see... ---->>
http://name.domain.com/welcome.aspx
Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink, "$1")
' result : name

but what if you get the url in realtime request.url.tostring ---->
request.url.tostring
Dim sdmlink As String = request.url.tostring
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink, "$1")
' result : the requested url

I added you to my msn cause I think your english isnt conversation quality
no offence :)
*Cool I don't see that you have added me. No offence taken :)

<to********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om...
--->how do I extract just 'name' -not- 'test/default.aspx?Id=name'


Strange that you ask this because you yourself add it in the code :

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink,
"test/default.aspx?Id=$1") & "<BR>")
' result : test/default.aspx?Id=name

your replace with : "test/default.aspx?Id=$1"

if you just want "name" do this :

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink, "$1") & "<BR>") ' '
result : name

But we already posted this.

I cleaner way to get the "name" is like this :

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write(sdm.Match(sdmlink).Groups(1))
' result : name

This produces only "name"

I added you to my msn cause I think your english isnt conversation quality
(no offence :)
If you still can't continue lets have a chat.

Nov 19 '05 #7
I got it thanks!

"Leon" <vn*****@msn.com> wrote in message
news:eJ**************@TK2MSFTNGP10.phx.gbl...
oh I see the problem, but don't know exactly how to fix it...see below

the follow code runs perfect when you pre include the url see... ---->>
http://name.domain.com/welcome.aspx
Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink, "$1")
' result : name

but what if you get the url in realtime request.url.tostring ---->
request.url.tostring
Dim sdmlink As String = request.url.tostring
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink, "$1")
' result : the requested url

I added you to my msn cause I think your english isnt conversation quality
no offence :)
*Cool I don't see that you have added me. No offence taken :)

<to********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om...
--->how do I extract just 'name' -not- 'test/default.aspx?Id=name'


Strange that you ask this because you yourself add it in the code :

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink,
"test/default.aspx?Id=$1") & "<BR>")
' result : test/default.aspx?Id=name

your replace with : "test/default.aspx?Id=$1"

if you just want "name" do this :

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink, "$1") & "<BR>") ' '
result : name

But we already posted this.

I cleaner way to get the "name" is like this :

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write(sdm.Match(sdmlink).Groups(1))
' result : name

This produces only "name"

I added you to my msn cause I think your english isnt conversation
quality (no offence :)
If you still can't continue lets have a chat.


Nov 19 '05 #8
And what was the problem? Rrealtime Request.url.tostring was not in the expected
format?

Cheers,
Tom Pester

PS Always isolate the poblem to the minimum before giving up on an anwser
yourself.
This means testing the problem code with your own input that you can control
easily.

I got it thanks!

"Leon" <vn*****@msn.com> wrote in message
news:eJ**************@TK2MSFTNGP10.phx.gbl...
oh I see the problem, but don't know exactly how to fix it...see
below

the follow code runs perfect when you pre include the url see...
---->>
http://name.domain.com/welcome.aspx
Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink, "$1")
' result : name
but what if you get the url in realtime request.url.tostring ---->
request.url.tostring
Dim sdmlink As String = request.url.tostring
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink, "$1")
' result : the requested url
I added you to my msn cause I think your english isnt conversation
quality
no offence :)
*Cool I don't see that you have added me. No offence taken :)
<to********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om...
--->how do I extract just 'name' -not- 'test/default.aspx?Id=name'

Strange that you ask this because you yourself add it in the code :

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink,
"test/default.aspx?Id=$1") & "<BR>")
' result : test/default.aspx?Id=name
your replace with : "test/default.aspx?Id=$1"

if you just want "name" do this :

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write("result : " & sdm.Replace(sdmlink, "$1") & "<BR>") '
'
result : name
But we already posted this.

I cleaner way to get the "name" is like this :

Dim sdmlink As String = "http://name.domain.com/welcome.aspx"
Dim sdm As New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
Response.Write(sdm.Match(sdmlink).Groups(1))
' result : name
This produces only "name"

I added you to my msn cause I think your english isnt conversation
quality (no offence :)
If you still can't continue lets have a chat.

Nov 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Bradley Plett | last post: by
10 posts views Thread by Lee Kuhn | last post: by
18 posts views Thread by Q. John Chen | last post: by
7 posts views Thread by norton | last post: by
7 posts views Thread by Billa | last post: by
6 posts views Thread by Ludwig | last post: by
3 posts views Thread by Zach | last post: by
25 posts views Thread by Mike | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.