Regular expression question?

Discussion in 'ASP .Net' started by Leon, Jun 16, 2005.

  1. Leon

    Leon Guest

    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
    Leon, Jun 16, 2005
    #1
    1. Advertising

  2. Leon

    Guest

    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
    >
    , Jun 17, 2005
    #2
    1. Advertising

  3. Leon

    Leon Guest

    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


    <> wrote in message
    news:...
    >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
    >>

    >
    >
    Leon, Jun 17, 2005
    #3
  4. Leon

    Guest

    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
    >
    > <> wrote in message
    > news:...
    >
    >> 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
    >>>
    , Jun 17, 2005
    #4
  5. Leon

    Leon Guest

    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!

    <> wrote in message
    news:...
    > 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
    >>
    >> <> wrote in message
    >> news:...
    >>
    >>> 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
    >>>>

    >
    >
    Leon, Jun 17, 2005
    #5
  6. Leon

    Guest

    > --->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
    , Jun 17, 2005
    #6
  7. Leon

    Leon Guest

    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 :)



    <> wrote in message
    news:...
    >> --->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.
    >
    >
    Leon, Jun 17, 2005
    #7
  8. Leon

    Leon Guest

    I got it thanks!

    "Leon" <> wrote in message
    news:...
    > 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 :)
    >
    >
    >
    > <> wrote in message
    > news:...
    >>> --->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.
    >>
    >>

    >
    >
    Leon, Jun 17, 2005
    #8
  9. Leon

    Guest

    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" <> wrote in message
    > news:...
    >
    >> 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 :)
    >> <> wrote in message
    >> news:...
    >>
    >>>> --->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.
    , Jun 17, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Munn

    Regular expression question...

    Andrew Munn, Jun 29, 2003, in forum: Perl
    Replies:
    1
    Views:
    2,125
    rakesh sharma
    Jun 30, 2003
  2. Glenn Kidd

    Regular expression question

    Glenn Kidd, Aug 18, 2003, in forum: Perl
    Replies:
    0
    Views:
    931
    Glenn Kidd
    Aug 18, 2003
  3. VSK
    Replies:
    2
    Views:
    2,287
  4. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    844
    Alan Moore
    Dec 2, 2005
  5. GIMME
    Replies:
    3
    Views:
    11,948
    vforvikash
    Dec 29, 2008
Loading...

Share This Page