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

Problems with appending parameter to url string

Last post 06-10-2009, 1:16 PM by mash. 1 replies.
Sort Posts: Previous Next
  •  06-10-2009, 12:36 PM 53812

    Problems with appending parameter to url string

    Hi,

    I've searched these forums for answers to this, but unfourtunately haven't found anything that directly answers my question.

    We need to append a parameter to all urls from a specific domain. This is for email newsletters so it is being achieved using find and replace in a text editor. We currently use the following expression:

    Find - (http.+example.com.+\?.+?)(")

    Replace - \1&id=1234\2

     

    This works to append a parameter to a url string that already has other parameters. e.g.

    http://www.example.com?param=first

    converts to

    http://www.example.com?param=first&id=1234

     

    Is there a way we can construct an expression that will append a parameter to any url, but will maintain the correct syntax. For example:

    http://www.example.com

    converts to

    http://www.example.com?id=1234

    AND

    http://www.example.com?param=first

    converts to

    http://www.example.com?param=first&id=1234

     

    I hope that makes sense.

    Thanks for any help

    Rich

     

     

     

     

  •  06-10-2009, 1:16 PM 53813 in reply to 53812

    Re: Problems with appending parameter to url string

    No, just using a single simple replace it can not be done, because you have different replacement values. One prefixed with an ampersand, one with a question mark.

    You'll either need code to determine which replacement to perform or mutliple passes with different replacements.


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
View as RSS news feed in XML