Home Download Buy Blog Forum Support

Regex Backreference Conditional Replace

Regex Backreference Conditional Replace

Postby alistairallan on Tue Oct 09, 2012 3:39 pm


I am trying to replace a url with some code, however sometimes the source url will contain a # and extra information and sometimes it won't.

I only want to insert

First URL with hash: http://someurl.com/test/#/testwithhash

Should be after replacement:
%%=RedirectTo(CONCAT('http://',@SUBDOMAIN,'someurl.com/test/', CHAR(35), '/testwithhas/'))=%%

Second URL without hash: http://someurl.com/testnohash/

Should be after replace:

So far I have this:
Find: (https?://)([\w./?=]+)(#?)([\w./?=]+)
Replace: %%=RedirectTo(CONCAT('$1',@SUBDOMAIN,'$2', CHAR(35), '$4'))=%%

This works for the first URL but adds an unwanted CHAR(35) for the second url.

But need to add some conditional formatting as even on the second URL I will insert a # CHAR(35)

I have seen a few mentions that suggest the replace supports backreferences but they don't see to work for me, am I missing something?

Posts: 1
Joined: Tue Oct 09, 2012 3:21 pm

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 30 guests