Learn how to a build a cloud-first strategyRegister Now


A question about Regrex

Posted on 2014-08-19
Medium Priority
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 85

Accepted Solution

ozo earned 900 total points
ID: 40271614
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 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 900 total points
ID: 40271629
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 35

Assisted Solution

by:Terry Woods
Terry Woods earned 200 total points
ID: 40271630
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

ID: 40271678
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.

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

810 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