Rich-text Reply

RegEx ... targeting a URL structure - can't get it to work

w-f 12-02-15
Accepted Solution

RegEx ... targeting a URL structure - can't get it to work

Hi guys,

 

I am trying to target certain URLs but I can not get it to work.

 

I want to target all URLs build up like this:

 

http://www.somedomain.com/fixed-subfolder/*.html

 

BUT do NOT include URLs like this:

 

http://www.somedomain.com/fixed-subfolder/*

 

 

So I tried around so many RegEx combinations, but  cannot get the URL targeting to work properly....

 

What I tried:

http://www.somedomain.com/fixed-subfolder/(*).html

http://www.somedomain.com/fixed-subfolder/(*).htm$

http://www.somedomain.com/fixed-subfolder/[a-z].html

http://www.somedomain.com/fixed-subfolder/[a-z].html$

....

 

 

Any idea what I am doing wrong here?

 

Any help is appreciated!

 

Best,

Florian

 

w-f
Level 2

Re: RegEx ... targeting a URL structure - can't get it to work

[ Edited ]

Hi Florian,

Thanks for your question!

I think what might help you is doing a quick and easy regex course: http://regexone.com/. It's very easy to quickly go through and allows you to do easy exercises too.

A regex that would work for you here is: www\.somedomain\.com\/fixed-subfolder\/.*\.html

The periods . and forward-slashes / have to be escaped, as they are special characters. Also, the asterisks denote that the character before it can occur 0 to many amount of times, so (*) means that the opening bracket ( can occur 0 to many times, then the closing bracket ) has to occur. The .* is what you're looking for, as the period . denotes any character, and the asterisk * denotes that any character may occur 0 to many times.

Then you can also use Optimizely's URL Match Validator to double-check that it works correctly.

I hope this helps!

Best,

w-f 12-04-15
 

Re: RegEx ... targeting a URL structure - can't get it to work

Hi Nils!

 

Ouch Smiley Sad I a n00b...thanks for helping out, working like a charm now!

 

Thank you!!

 

Best,

Florian

w-f
Level 2