Making RegEx searches case-insensitive

Posted on 2006-04-03
Last Modified: 2010-04-23
I’m using 1.1 with Visual Studio 2003 (   I have a program that checks a url to make sure it’s valid and that it is a pdf file.  What I want to do is make it so the check is case-insensitive.  Below you can see how I used “[pP][dD][fF]” to make the search for “pdf” case-insensitive, but I don’t want to do it that way (I may want to later make other parts case-insensitive).

I see in the Help that there is an “IgnoreCase” option, but I don’t know how to utilize it.

The first line below makes the url criteria, then the conditional statement checks to see if the url is how I require it to be.  But I don’t see how to make it case-insensitive.  I don’t see how I would use “urlRegEx.Options.IgnoreCase”.  Can you help?  Thank you!

(pdfFileUrl is the url itself)

        urlRegEx = New Regex("^(http[s]?://).+[pP][dD][fF]$")
            If urlRegEx.IsMatch(pdfFileUrl) Then
                Trace.Warn("urlRegEx", "Url should be okay.")
                Trace.Warn("urlRegEx", "Url failed!")
            End If
Question by:psmithphil
    LVL 37

    Expert Comment

    by:Harisha M G
    Hi, try this:

    urlRegEx.IsMatch(pdfFileUrl, RegEx.Options.IgnoreCase)

    LVL 62

    Accepted Solution

    Hi psmithphil;

    Just change this line in your code

    urlRegEx = New Regex("^(http[s]?://).+[pP][dD][fF]$")

    To this:

    urlRegEx = New Regex("^(http[s]?://).+pdf$", RegexOptions.IgnoreCase)


    Author Comment

    Thank you both!

    Fernando, what you showed me worked perfectly.  Now that I see it, I can see why it would work.  Mgh's was close but it wouldn't show up in Intellisense so it wasn't available.

    This makes life a lot easier.  Thank you!
    LVL 62

    Expert Comment

    by:Fernando Soto
    Glad I was able to help. :=)

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    745 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

    16 Experts available now in Live!

    Get 1:1 Help Now