A question about Regrex

Posted on 2014-08-19
Last Modified: 2014-08-19
Hi experts
I am using this regrex expression:

Open in new window

My intention was to restricted inputs to '0'-'9', 'A'-'F', 'I', 'X', '#', '*'.
But it still allows me to enter 'G', 'H', etc.
Could someone tell me where I had done incorrectly.

Question by:dominicwong
    LVL 84

    Accepted Solution

    The range *-^ includes 'G', 'H', etc.
    If your intention was to restricted inputs to'0'-'9', 'A'-'F', 'I', 'X', '#', '*', '-', '^', '\b'
    then you could backquote the last -
    LVL 74

    Assisted Solution

    by:käµfm³d 👽
    Just to add to ozo's comment, a hyphen inside of square brackets indicates a range of characters to find. You would need to look at the ASCII table to see which characters fall into your range. To avoid having the regex engine interpret a hyphen as a range, you either need to escape it (or "backquote" it, as ozo refers to it) by using a backslash, or you need to place it as either the very first character or the very last character of your bracket expression. So in other words, all of the following are exactly equivalent:


    Open in new window

    LVL 34

    Assisted Solution

    by:Terry Woods
    No points please because @ozo has solved it.

    Just wanted to say that the code change should look like this:

    Open in new window


    Author Closing Comment

    Thanks ozo for your quick response and help.
    Thanks kaufmed for going the extra mile to give me a very good explanation.
    Thanks also to Terry for your help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 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

    20 Experts available now in Live!

    Get 1:1 Help Now