473,583 Members | 3,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regular expression question?

My web application allow the user to enter the site by typing in a subdomain
such as 'name.domain.co m'. 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.ToS tring

Dim sdm As Regex

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

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

Test 2.............. ..name.domain.c om
Dim sdmlink As String = Request.Url.ToS tring

Dim sdm As Regex

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

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


Nov 19 '05 #1
8 1423
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(sd mlink, "$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.co m'. 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.ToS tring
Dim sdm As Regex

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

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

Test 2.............. ..name.domain.c om
Dim sdmlink As String = Request.Url.ToS tring
Dim sdm As Regex

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

Context.Items(" Test") = (sdm.Replace(sd mlink,
"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_Beg inRequest(ByVal sender As Object, ByVal e As EventArgs)

' Fires at the beginning of each request

Dim sdmurl As String = Request.Url.ToS tring

Dim sdm As Regex

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

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

End Sub
<to************ ********@pandor a.be> wrote in message
news:a1******** *************** ***@news.micros oft.com...
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(sd mlink, "$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.co m'. 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.ToS tring
Dim sdm As Regex

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

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

Test 2.............. ..name.domain.c om
Dim sdmlink As String = Request.Url.ToS tring
Dim sdm As Regex

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

Context.Items(" Test") = (sdm.Replace(sd mlink,
"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(sdm link, "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_Beg inRequest(ByVal sender As Object, ByVal e As
EventArgs)
' Fires at the beginning of each request

Dim sdmurl As String = Request.Url.ToS tring

Dim sdm As Regex

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

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

End Sub

<to************ ********@pandor a.be> wrote in message
news:a1******** *************** ***@news.micros oft.com...
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(sd mlink, "$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.co m'. 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.ToS tring
Dim sdm As Regex
sdm = New Regex("http://(?!www\.)(.*)(\ .domain\.com.*) ")

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

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

Context.Items(" Test") = (sdm.Replace(sd mlink,
"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************ ********@pandor a.be> wrote in message
news:a1******** *************** ***@news.micros oft.com...
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(sdm link,
"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_Beg inRequest(ByVal sender As Object, ByVal e As
EventArgs)
' Fires at the beginning of each request

Dim sdmurl As String = Request.Url.ToS tring

Dim sdm As Regex

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

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

End Sub

<to************ ********@pandor a.be> wrote in message
news:a1******** *************** ***@news.micros oft.com...
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(sd mlink, "$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.co m'. 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.ToS tring
Dim sdm As Regex
sdm = New Regex("http://(?!www\.)(.*)(\ .domain\.com.*) ")

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

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

Context.Items(" Test") = (sdm.Replace(sd mlink,
"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(sdm link, "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(sdm link, "$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(sdmli nk).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(sdm link, "$1")
' result : name

but what if you get the url in realtime request.url.tos tring ---->
request.url.tos tring
Dim sdmlink As String = request.url.tos tring
Dim sdm As New Regex("http://(?!www\.)(.*)(\ .domain\.com.*) ")
Response.Write( "result : " & sdm.Replace(sdm link, "$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************ ********@pandor a.be> wrote in message
news:a1******** *************** ***@news.micros oft.com...
--->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(sdm link,
"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(sdm link, "$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(sdmli nk).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.co m> wrote in message
news:eJ******** ******@TK2MSFTN GP10.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(sdm link, "$1")
' result : name

but what if you get the url in realtime request.url.tos tring ---->
request.url.tos tring
Dim sdmlink As String = request.url.tos tring
Dim sdm As New Regex("http://(?!www\.)(.*)(\ .domain\.com.*) ")
Response.Write( "result : " & sdm.Replace(sdm link, "$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************ ********@pandor a.be> wrote in message
news:a1******** *************** ***@news.micros oft.com...
--->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(sdm link,
"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(sdm link, "$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(sdmli nk).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.tos tring 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.co m> wrote in message
news:eJ******** ******@TK2MSFTN GP10.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(sdm link, "$1")
' result : name
but what if you get the url in realtime request.url.tos tring ---->
request.url.tos tring
Dim sdmlink As String = request.url.tos tring
Dim sdm As New Regex("http://(?!www\.)(.*)(\ .domain\.com.*) ")
Response.Write( "result : " & sdm.Replace(sdm link, "$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************ ********@pandor a.be> wrote in message
news:a1******** *************** ***@news.micros oft.com...
--->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(sdm link,
"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(sdm link, "$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(sdmli nk).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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9728
by: Vibha Tripathi | last post by:
Hi Folks, I put a Regular Expression question on this list a couple days ago. I would like to rephrase my question as below: In the Python re.sub(regex, replacement, subject) method/function, I need the second argument 'replacement' to be another regular expression ( not a string) . So when I find a 'certain kind of string' in
5
2508
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL, and then reconstruct another URL based on it. For example, I need to scan a web page looking for something like <a...
10
3009
by: Lee Kuhn | last post by:
I am trying the create a regular expression that will essentially match characters in the middle of a fixed-length string. The string may be any characters, but will always be the same length. In other words, as the regular expression (....)($) matches the "4567" in the string "1234567", how would I create a similar regular expression that...
18
3022
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How ??
5
3096
by: Ryan | last post by:
HELLO I am using the following MICROSOFT SUGGESTED (somewhere on msdn) regular expression to validate email addresses however I understand that the RFP allows for "+" symbols in the email address and this method does not.... Does anyone have an explanation? Function IsValidEmail(ByVal strIn As String) As Boolean
7
371
by: norton | last post by:
Hello, Does any one know how to extact the following text into 4 different groups(namely Date, Artist, Album and Quality)? - Artist - Album Artist - Album - Artist - Album - Artist - Album- i have try this syntax but it failed
7
3806
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way...
6
2287
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not work: it seems that < is not a valid character, so the beginning of the word starts at theletter 'p' instead of '<'. Because I'm not an expert in...
3
2554
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular expression. ^(.+?) uses (?!a spoon)\.$
25
5140
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How do I gain access...
0
7894
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7821
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7929
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6577
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5697
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5370
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1424
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1152
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.