Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Regex to find and replace string in URL

Last post 04-16-2009, 2:30 PM by SimonTurner. 0 replies.
Sort Posts: Previous Next
  •  04-16-2009, 2:30 PM 52302

    Regex to find and replace string in URL

    Hi all,

    I'm attempting to create a custom regex expression in ASP.Net and could use a little help.

    I need to create a Regex to rewrite the URL’s in the /profiles/ section of my WorkoutBOX the site.   Here are some examples of what I need done:

    Rewrite from:

    www.workoutbox.com/profiles/sampleusername
    www.workoutbox.com/profiles/simonturner


    To:

    www.workoutbox.com/profiles/username/sampleusername
    www.workoutbox.com/profiles/username/simonturner

     

    NB - "/username/" is just a static string and does not mean the username of a logged on user.
     
    I'm working with a custom URL Rewriting tool that accepts a lookFor regex and a rewriteTo regex.  Here is the entry in the config file where i need to put the regex's:

    <parameterRewrite name="ProfileRewrite" tabNames="Profiles" lookFor="" rewriteTo="" />

    Here's an example of a working set of regex's to rewrite a custom URL:

        <!-- this rule is for rewriting ventrian news articles from a format of /2/article-name where '2' is the article id, and 'article-name' is the SEO name generated by the NA module -->
        <parameterRewrite name="ventrian news articles"  tabNames="Articles;Products" lookFor="(?&lt;!articletype/articleview/articleid)(?:/|^)(?&lt;artid&gt;\d+)/(?&lt;artname&gt;[^&amp;][\w\d-]+)" rewriteTo="articletype=articleView&amp;articleId=$1&amp;$2" />

    Would really appreciate some help on this one, I'm a pretty decent programmer but have absolutly no idea when it comes to regular expressions.

    Thanks again,

     

    Simon Turner

    Filed under: , ,
View as RSS news feed in XML