Regular expressions to include and exclude webside subdirectories

Posted on 2012-09-20
Last Modified: 2012-09-27
I have a website content management program that can include or exclude webpages from being processed in a certain way.  

And the documentation says I can use "regular expressions" to do it.  Specifically following the documentation on regular  expressions at  this url    And the documentation says I can test them at

However I'm not quite sure on how to do it.  I have little or no experience on "regular expressions".  This is the first I have heard of it. However I certainly know dos wildcards such as *.* and ?.  But that's my limit.

Here are example urls I am trying to include and exclude using "regular expressions:

I want "" to be EXcluded, using regular expressions, but I want its subdirectory "" to be INcluded.

So pages such as and and
...would be EXcluded from being processed in a certain way by the content management system.

But pages such as
...would be INcluded to be processed in a certain way by the content management system.

Also it would be ideal if anything in the bananas subdirectories would be INcluded via a wildcard expression -- so that I wouldn't have to manually have to type each page into the system.

Any suggestions?  


Question by:Rowby Goren
    LVL 34

    Accepted Solution

    Using the regex tester you linked to, the pattern:

    Open in new window

    gives the result you want. You may need to exclude the ^ and $ (which match the start and end of line in multiline mode, which I used for testing), and possibly even the http://wwwfoobar\.org/ part too depending on what the software is expecting. You'll need to play around and find what works, or find out more about the system you're using.

    I tested on the data:

    Open in new window

    And the result looks like this for me:
    LVL 34

    Expert Comment

    by:Terry Woods
    A note about negative lookaheads: In regular expressions, the pattern
    uses a negative lookahead so that foo is only matched when it's not followed by bar

    This pattern matches foo, when not followed by bar, then the next 2 (non-linebreak) characters:
    eg when used with text:

    Open in new window

    You'd get the following matches:
    fooba (from foobaa)
    foofi (from foofighters)

    The pattern I gave you used a negative lookahead within a negative lookahead. Let me know if you can't get your head around the concept!

    (fingers crossed your system supports negative lookaheads; not all regex engines do support them)
    LVL 9

    Author Comment

    by:Rowby Goren
    Thanks Terry.  

    I will be testing this later today or first thing in the morning.

    Thanks for helping.  

    On a side note, I assume "regular expressions" are is also used for programming syntax, such as in php programming?   BTW the content management system I am using was done in php and is called Joomla.  I've added an extension that uses regular expressions to  fine tune its features.


    LVL 34

    Expert Comment

    by:Terry Woods
    PHP, Perl, Java and .NET have very good regex engines and would work with the pattern I provided, so you should be ok.
    LVL 9

    Author Comment

    by:Rowby Goren
    Hi  Sorry for the delay. I was out all weekend at a convention. But will try out the solution this afternoon.

    LVL 9

    Author Comment

    by:Rowby Goren
    Thanks Terry,  Worked fine!


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
    Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
    In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
    In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now