Solved

MutableTable Regular Expression

Posted on 2011-09-21
9
197 Views
Last Modified: 2012-05-12
Hello,

I have a global constant that allows the validation of fields from a MutableTable.

    public static final String POINT_GROUP_REGEX = "[^\\r\\n\\t]*";

    public static final String POINT_GROUP_REGEX = "[^|;&\\r\\n\\t]*";

to take into account the special characters. |&;
Is that all that is required to fix this bug ?

Paolo
0
Comment
Question by:ptreves
  • 5
  • 3
9 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36577299
Yes. If you wanted to match a | character without listing other possible characters in [] brackets, you'd need to escape it like \\| but it's ok while it's contained in [] brackets.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 36577300
That should work, yes.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 36577302
I'm a little confused though what this has to do with Mutable Tables...
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36577304
Note also that your pattern is matching ^ as a character, not as a start-of-string placeholder; I'm not sure whether that's what you intended.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 35

Expert Comment

by:Terry Woods
ID: 36577313
And actually, I wonder if the expression is a bit meaningless in the first place. The * after the characters in [] allows zero characters to be matched, which probably isn't what you want. Maybe you want:
    public static final String POINT_GROUP_REGEX = "[^|;&\\r\\n\\t]+";
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36577317
Changing the * to + means the pattern requires at least one of the listed characters.
0
 

Author Comment

by:ptreves
ID: 36580574
Changing the quantifier from * to +, as follows:

    public static final String POINT_GROUP_REGEX = "[^|;&\\r\\n\\t]+";

What I realy want is to prevent users from entering any of the three special characters  |;& in a mutable table used for "Group Names". As soon as a user enters any of those three special characters or any of the control characters, he should be prompted to change/correct his entry.

Here is the java routine that processes the Regular Expression:

        ColumnTableModel pointGroupsModel;
        Column groupID = getColumn(messages.getString("GroupIDTxt"), false, SystemwideConstants.POINT_GROUP_ID_ATTR, Integer.class, null,
                false, null);

        Column pointGroupName = getStringColumn(messages.getString("GroupNameTxt"), SystemwideConstants.POINT_GROUP_NAME_ATTR,
                new RegexEditor(SystemwideConstants.POINT_GROUP_REGEX, new InvalidStringHandler(messages.getString("GroupNameTxt"))));

        Column[] columns = new Column[]{groupID, pointGroupName};
        pointGroupsModel = new ColumnTableModel(columns, stemwideConstants.MAX_NUMBER_OF_POINT_GROUPS);

The problem is that after compiling and testing the code, the user can still enter those special characters.
Is the regular expression at fault ?

Paolo
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 36580777
Q: Is the regular expression at fault ?
A: Perhaps...

   Where, and how is the RegExp used?  Are we talking about a code in your setValueAt() method?
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 36583894
The pattern:
"[^|;&\\r\\n\\t]+"
will match when it detects one or more of the characters specified, in which case you want the validation code to prompt the user for a correction. Note that if just one character in the specified list makes the value invalid, then the + is redundant (as the "or more" part of the "one or more" meaning of it is unnecessary; therefore this pattern would do the trick:
"[^|;&\\r\\n\\t]"
but you need to get the surrounding logic of your code right too!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
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…

747 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