Regular Expression within an IF statement.

Posted on 2006-03-30
Last Modified: 2012-05-05
I was wondering if I could use reg-expression within an IF statement, like so...

while($file[$i] = readdir($dp3))
    if($file[$i] != '.' && $file[$i] != '..' && $file[$i] != 'dsc_[\s\S]*?.jpg')
            { echo $file[$i]; }

The reg-ex im using is

It's not working for me, is it possible? If not I need some code to get the same result.
Question by:bertmn
    LVL 49

    Accepted Solution

    if($file[$i] != '.'&& $file[$i] != '..'&& !preg_match('/^dsc_(.*)\.jpg$/i', $file[$i])) {


    Author Comment

    Thanks Roonaan :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Suggested Solutions

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    759 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

    10 Experts available now in Live!

    Get 1:1 Help Now