473,322 Members | 1,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Regular Expression Help (URL Rewriting)

I'm working on a URL rewriting engine at the moment and would like to
make it more dynamic. I am doing this via Global.asax and as of now I
have to manually write the URL's one-by-one. I am wanting to use a RegEx
on a string and then access the dynamic page this way. For example:

Let's say that the static URL I implement is:

Wonkas_widgets_factory_Tonka_Truck_002.aspx

I would want this to point to:

product.aspx?productID=002

To accomplish this I would simply need to use the RegEx:
\d{3}

Now let's say that I have the following code in Application_BeginReguest
(Global.asax):

Sub Application_BeginRequest(ByVal sender as Object, ByVal e as
EventArgs)

Dim httpContext As System.Web.HttpContext = httpContext.Current
Dim currentURL As String = Request.Path.ToLower()

If currentURL.IndexOf("Willy_Wonkas_widget_factory_00 1") > 0 Then
httpContext.RewritePath("product.aspx?productID=00 1")

End Sub

What would be the best way to implement this RegEx so that I can create
many static URL's?

*** Sent via Developersdex http://www.developersdex.com ***
Nov 26 '05 #1
2 1101
I'm sure I can help with regular expressions, but I don't understand
what you're asking.

Nov 27 '05 #2
Sorry,

I couldn't figured this out earlier. I should've posted a reply to
myself.

Sub Application_BeginRequest(ByVal sender as Object, ByVal e as
EventArgs)

Dim httpContext As System.Web.HttpContext = httpContext.Current
Dim currentURL As String = Request.Path.ToLower()

Dim strPattern As String = "page(\d+).aspx"

Dim objRegEx As Regex
Dim Matches As MatchCollection
Dim pageID As string
objRegEx = New Regex(strPattern, RegexOptions.IgnorePatternWhitespace)
Matches = objRegEx.Matches(currentURL)

If Matches.Count > 0 Then
pageID = Matches(0).Groups(1).ToString()
httpContext.RewritePath("product.aspx?productID=" & pageID)
Else
httpContext.RewritePath(currentURL)
End If

*** Sent via Developersdex http://www.developersdex.com ***
Nov 27 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
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,...
0
by: radawson218 | last post by:
Hi, I'm a complete newbie when using regular expressions, so forgive me if my delimma sounds stupid. I have an ASP.NET app that utilizes url rewriting. It's a simple bookstore that allows...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
2
by: Dot net work | last post by:
Hello. Say I have a .net textbox that uses a .net regularexpressionvalidator. If the regular expression fails, is it possible to launch a small client side javascript function to do something,...
0
by: Anthony | last post by:
Hi there, i am trying to perform url rewriting using regular expressions and am after a little performance advice as regular expressions just baffle me: Basically my site has only one style...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
9
by: Pete Davis | last post by:
I'm using regular expressions to extract some data and some links from some web pages. I download the page and then I want to get a list of certain links. For building regular expressions, I use...
25
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...
10
by: venugopal.sjce | last post by:
Hi Friends, I'm constructing a regular expression for validating an expression which looks as any of the following forms: 1. =4*++2 OR 2. =Sum()*6 Some of the samples I have constructed...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.