Keystroke regular expression (regex) problem

I have a text field that should only permit the following values: "V", "X" or "NA" (all uppercase).
I'm fairly OK with javascript in pdf and I have a script that validates these when the field losses focus.
What would be much better is to have a keystroke script that only permits these values to be entered. I've found elsewhere in the forums a useful starting point here:
var re = /^[A-Za-z0-9 :\\_]$/;
event.change = event.change.toUpperCase();
if (event.change.length >0) {
if (event.willCommit == false) {
    if (!re.test(event.change)) {
        event.rc = false
but I've been unable to come up with anything for the regexp pattern that works reliably (these are definitely not my strong point).
Grateful thanks for any help.

You can apply the RegEX to the keystroke and restrict the keystroke values that be entered or you can use the validation tab to enter a script to restrict the input to specific values.
The script you are using only checks the entered character so it will not test the string "NA" which is 2 characters.
Another approach for such a limited number of input options would be a combo box  or drop down box where the options are space, "V", "X", and "NA". The value of the field would then be limited to a space (no selection made), a V, X, or NA.

Similar Messages

  • Regular Expression compilation problem

    I am trying to use JDK 1.4's regular expression classes to match text that appears with curly braces (e.g. {field1}) using the following regular expression:
    [{]([0-9A-Za-z]+)[}]
    I use this same pattern with the org.apache.regexp and org.apache.oro packages without any problem, but get the following error when running it using the new java.util.regex package in JDK 1.4:
    Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected character '?' near index 0
    [{]([0-9A-Za-z]+)[}]
    ^
    at java.util.regex.Pattern.error(Pattern.java:1472)
    at java.util.regex.Pattern.range(Pattern.java:2052)
    at java.util.regex.Pattern.clazz(Pattern.java:1991)
    at java.util.regex.Pattern.sequence(Pattern.java:1529)
    at java.util.regex.Pattern.expr(Pattern.java:1489)
    at java.util.regex.Pattern.compile(Pattern.java:1257)
    at java.util.regex.Pattern.<init>(Pattern.java:1013)
    at java.util.regex.Pattern.compile(Pattern.java:760)
    at Test_jdk14.main(Test_jdk14.java:13)
    What am I doing wrong?
    Thanks, Tony

    Hello,
    Let's look at what you've done.
    [\\{]([0-9A-Za-z]+)[}]Okay, first you escape the opening curly brace, but you did not escape the closing curly brace.
    [\\{]([0-9A-Za-z]+)[\\}]Next, you use the square brackets, but you only have one thing in the brackets, so, they are unnecessary:
    \\{([0-9A-Za-z]+)\\}Next, I am going to contract all that stuff inside your remaining square brackets to \\w, since that covers 0-9A-Za-z_
    \\{(\\w+)\\}Now, are you expecting any sort of spaces within the curly brackets? If so, you didn't specify them. I'll assume you didn't.
    Now you did all this, but it still doesn't match what you thought it would match. Did you use Matcher.matches or Matcher.lookingAt?
    If you look at the API for these methods, you'll see that
    a) Matcher.matches(...) only returns true if the entire input sequence matches the pattern.
    b) Matcher.lookingAt(...) only returns true if the start of the input sequence matches the pattern.
    In either of these cases, if your string didn't start with the opening bracket, then the Pattern (in its current form) won't match. For example:
    "{text1}"                       // matches() == true
                                    // lookingAt() == true
    "{text2} blah blah"             // matches() == false
                                    // lookingAt() == true
    "blah blah {text3}"             // matches() == false
                                    // lookingAt() == false
    "blah blah {text4} blah blah"   // matches() == false
                                    // lookingAt() == false
                                    //You would want to use Matcher.find() if you want to find all of these matches.
    However, there is a way to find those matches using Matcher.matches() and Matcher.lookingAt(). All you have to do is put .* in front and behind the thing you're looking for.
    .*\\{([\\w]+)\\}.*This way, any number of characters can come before or after your pattern, and it will still fit the requirements.
    Here's an example:
    import java.util.*;
    import java.util.regex.*;
    public class RegExample
       public static void main( String [] args )
          Pattern p = Pattern.compile( ".*\\{(\\w+)\\}.*" );
          Matcher m = p.matcher( "blah blah {field1} blah blah" );
          if ( m.lookingAt() )
             System.out.println( "We're looking at it." );
          if ( m.matches() )
             System.out.println( "It matches." );
          m.reset();
          if ( m.find() )
             System.out.println( "we found the first match" );
             System.out.println( "It was: " + m.group(1) );
    }

  • Regular Expression escaping problem!

    Hi all,
    Well as you know characters such as '*' and '?' are reserved characters in regular expression so I suppose if I want to find the exact character (a '?' for example) in a string, I have to escape it with a backslash:
    str=str.replaceAll("\?","a");
    In the statement above, I need to replace all question marks with another character but it has a compile error:
    Error(116,48): invalid escape character
    to my surprise this following code does the job while it should be interpreted as: one occurance of the '\' character or nothing at all:
    str=str.replaceAll("\\?","a");
    What's the problem? what's the general rule on escaping such characters?

    I think you're right.
    The point is that java first interprets the String and handle its own scape characters then the result would be passed on to reqular expression parser.
    so I guess in order to search for one occurance of the '\' character or nothing at all the java string would be:
    so that the input to reqular expression parser would be:
    while in the first situation:
    a "\\?" java string is first trasformed into \? which will be considerd as one occurance '?' in reqular expression point of view...
    Message was edited by:
    nerssi
    Message was edited by:
    nerssi

  • Regular Expression Validator Problem

    Hi,
    I have a text area that I want to use a regular expression
    validator on to verify that one or more 9 char alphanumeric serial
    numbers were entered.
    <mx:RegExpValidator
    source="{entryField}"
    property="text"
    flags="gi"
    expression="{/[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0- 9][a-zA-Z0-9][a-zA-Z0-9](
    |,|\\n|\\r|\\t)/}"
    valid="handleResult(event)"
    invalid="handleResult(event)"
    trigger="{entryField}"
    triggerEvent="textInput"
    />
    //for testing
    private function
    handleResult(eventObj:ValidationResultEvent):void {
    if (eventObj.type == ValidationResultEvent.VALID)
    entryField.setStyle("borderColor", "green");
    entryField.setStyle("borderThickness", "2");
    else
    entryField.setStyle("borderColor", "red");
    entryField.setStyle("borderThickness", "2");
    The problem is the handler function always comes back
    invalid, even when it should be valid, such as: 123456789 a12345678
    lk231jkop
    Can anyone advise where I might be going wrong?
    Thanks!

    This is weird, i just tried your RegExp using the Adobe's
    Live Docs example and it worked perfectly.
    Try it at:
    http://livedocs.adobe.com/flex/201/langref/mx/validators/RegExpValidator.html
    Scroll down to the end of the page, then type your RegExp and
    your TestValue and click the Validate button, it works. I am
    guessing that maybe it is your
    i
    flag, try removing it from your validator.
    Hope this helps

  • Regular expression (regex) help!

    I am trying to write a correct regular expression but am having difficulties.
    I have a webpage saved as a string and want to extract all the links (urls) from the webpage string.
    The trouble I am having is that some websites surround links using double quotes " " and some use single quotes ' ' around links in html:
    Double quotes around url:
    <a href="www.example.com"></a>
    And single quotes:
    <a href="www.example.com"></a>
    So far I have a regex which extract links if they are surrounded with double quotes (see below), however if a page uses single quotes it screws up ;)
    Pattern.compile("<a\\s+href\\s*=\\s*\"?(.*?)[\"|>]",  Pattern.CASE_INSENSITIVE);So is there a way to say look for double quotes OR single quotes?
    Many thanks
    null

    There's no need to escape the single-quote (or apostrophe) in a regex. The only reason it was necessary to escape the double-quote (or quotation mark) is because the regex was written in the form of a String literal. Neither the single-quote or the double-quote has any special meaning in regexes.

  • Regular Expression wierdness - problem with $ character

    If I use the following KM code in Beanshell Technology - it works correctly and replaces "C$_0MYREMOTETABLE RMTALIAS, MYLOCALTABLE LOCALIAS, " with "C$_0MYREMOTETABLE_000111 RMTALIAS, MYLOCALTABLE LOCALIAS, "
    But when I try to use the same exact code in 'Undefined' technology - it does not match anything in the source string - and does not replace anything.
    If I change the regular expression to not use the $ it still does not work.
    But if I change the source string to remove the $ - then the regular expression works.
    If I use the same code in Beanshell technology - it works fine - but then I can't use the value in a later 'Undefined' technology step.
    Does anyone know if the java technology does something special with $ characters when ODI parses the KM code?
    Does anyone know if there is a way to use the value from a Beanshell variable in a 'Undefined' technology step?
    String newSourceTableList = "";
    String sessionNum ="<%=odiRef.getSession("SESS_NO") %>";
    String sourceTableList = "<%=odiRef.getSrcTablesList("", "[WORK_SCHEMA].[TABLE_NAME] [POP_TAB_ALIAS]" , ",", ",") %>";
    String matchExpr = "(C\\$_\\S*)"; (should end with two backslashes followed by 'S*' - this editor mangles it)
    String replaceExpr = "$0_"+sessionNum+ " ";
    newSourceTableList = sourceTableList.replaceAll(matchExpr,replaceExpr);
    ---------------------------------------------------

    Phases of substitution in ODI:
    The way ODI works allows for three separate phases of substitution, and you can use them all. The three phases are:
    - First Phase: <% %> You will see these appear in the knowledge moduiles etc and these are substituted on generation. (when you generate a scenario, or tell ODI to execute an interface directly) this phase is used to generate the column names, table names etc which are known from the metadata at that phase.
    - Second Phase: <? ?> This phase is substituted when the scenario is instatntiuated as an excution - session generation. At this point, ODI has the additional information which allows it to generate the schema names, as it has resolved the Logical/Physical Schemas through the use of the Context (which is provided for the execution to take place. All the substitutions at this point are written to the execution log.
    - Third Phase <@ @> This phase is substituted when the execution code is read from the session log for execution. You will note that anything substituted in this phase is NEVER written to the execution log. (see PASSWORDS as a prime example, you don't want those written to the logs, with the security risks associated with that!)
    Anything in <@ @> is always interpreted for substitution by the java beanshell, it does not have to be a Java Beanshell step, it can be any kind of step, it will be interpreted at that run-time point.

  • Urgent!!! Problem in regular expression for matching braces

    Hi,
    For the example below, can I write a regular expression to store getting key, value pairs.
    example: ((abc def) (ghi jkl) (a ((b c) (d e))) (mno pqr) (a ((abc def))))
    in the above example
    abc is key & def is value
    ghi is key & jkl is value
    a is key & ((b c) (d e)) is value
    and so on.
    can anybody pls help me in resolving this problem using regular expressions...
    Thanks in advance

    "((key1 value1) (key2 value2) (key3 ((key4 value4)
    (key5 value5))) (key6 value6) (key7 ((key8 value8)
    (key9 value9))))"
    I want to write a regular expression in java to parse
    the above string and store the result in hash table
    as below
    key1 value1
    key2 value2
    key3 ((key4 value4) (key5 value5))
    key4 value4
    key5 value5
    key6 value6
    key7 ((key8 value8) (key9 value9))
    key8 value8
    key9 value9
    please let me know, if it is not possible with
    regular expressions the effective way of solving itYes, it is possible with a recursive regular expression.
    Unfortunately Java does not provide a recursive regular expression construct.
    $_ = "((key1 value1) (key2 value2) (key3 ((key4 value4) (key5 value5))) (key6 value6) (key7 ((key8 value8) (key9 value9))))";
    my $paren;
       $paren = qr/
               [^()]+  # Not parens
             |
               (??{ $paren })  # Another balanced group (not interpolated yet)
        /x;
    my $r = qr/^(.*?)\((\w+?) (\w+?|(??{$paren}))\)\s*(.*?)$/;
    while ($_) {
         match()
    # operates on $_
    sub match {
         my @v;
         @v = m/$r/;
         if (defined $v[3]) {
              $_ = $v[2];
              while (/\(/) {
                   match();
              print "\"",$v[1],"\" \"",$v[2],"\"";
              $_ = $v[0].$v[3];
         else { $_ = ""; }
    C:\usr\schodtt\src\java\forum\n00b\regex>perl recurse.pl
    "key1" "value1"
    "key2" "value2"
    "key4" "value4"
    "key5" "value5"
    "key3" "((key4 value4) (key5 value5))"
    "key6" "value6"
    "key8" "value8"
    "key9" "value9"
    "key7" "((key8 value8) (key9 value9))"
    C:\usr\schodtt\src\java\forum\n00b\regex>

  • Problem in creating a Regular Expression with gnu

    Hi All,
    iam trying to create a regular expression using gnu package api..
    gnu.regex.RE;
    i need to validate the browser's(MSIE) userAgent through my regular expression
    userAgent is like :First one ==> Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
    i wrote an regular expression like this:
    Mozilla.*(.*)\\s*(.*)compatible;\\s*MSIE(.*)\\s*(.*)([0-9]\\.[0-9])(.*);\\s*(.*)Windows(.*)\\s*NT(.*)\\s*5.0(.*)
    Actaully this is validating my userAgent and returns true, my problem is, it is returning true if userAgent is having more words at the end after Windows NT 5.0 like Second One ==> Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) Testing
    i want the regularExpression pattern to validate the First one and return true for it, and has to return false for the Second one..
    my code is:
    import gnu.regexp.*;
    import gnu.regexp.REException;
    public class TestRegexp
    public static boolean getUserAgentDetails(String userAgent)
         boolean isvalid = false;
         RE regexp = new RE("Mozilla.*(.*)\\s*(.*)compatible;\\s*MSIE(.*)\\s*(.*)([0-9]\\.[0-9])(.*);\\s*(.*)Windows(.*)\\s*NT(.*)\\s*5.0(.*)");
         isvalid = regexp.isMatch(userAgent);
         return isvalid;
    public static void main(String a[])
         String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
         boolean regoutput = getUserAgentDetails(userAgent);
         System.out.println("***** regoutput is ****** " + regoutput);
    }please help me in solving this..
    Thanks in Advance..
    thanx,
    krishna

    Ofcourse, i can do comparision with simple string matching..
    but problem is the userAgent that i want to support is for all the MSIE versions ranging from 5.0 onwards, so there will the version difference of IE like MSIE 6.0..! or MSIE 5.5 some thing like that..
    any ways i will try with StringTokenizer once..!
    seems that will do my work..
    Thanks,
    krishna

  • Problems with java regular expressions

    Hi everybody,
    Could someone please help me sort out an issue with Java regular expressions? I have been using regular expressions in Python for years and I cannot figure out how to do what I am trying to do in Java.
    For example, I have this code in java:
    import java.util.regex.*;
    String text = "abc";
              Pattern p = Pattern.compile("(a)b(c)");
              Matcher m = p.matcher(text);
    if (m.matches())
                   int count = m.groupCount();
                   System.out.println("Groups found " + String.valueOf(count) );
                   for (int i = 0; i < count; i++)
                        System.out.println("group " + String.valueOf(i) + " " + m.group(i));
    My expectation is that group 0 would capture "abc", group 1 - "a" and group 2 - "c". Yet, I I get this:
    Groups found 2
    group 0 abc
    group 1 a
    I have tried other patterns and input text but the issue remains the same: no matter what, I cannot capture any paranthesized expression found in the pattern except for the first one. I tried the same example with Jakarta Regexp 1.5 and that works without any problems, I get what I expect.
    I am using Java 1.5.0 on Mac OS X 10.4.
    Thank to all who can help.

    paulcw wrote:
    If the group count is X, then there are X plus one groups to go through: 0 for the whole match, then 1 through X for the individual groups.It does seem confusing that the designers chose to exclude the zero-group from group count, but the documentation is clear.
    Matcher.groupCount():
    Group zero denotes the entire pattern by convention. It is not included in this count.

  • Regular expression and line break problem

    Hi friends,
    I was trying out one regular expression in java but, for some reasons its not working. The test string looks something like this in the eclipse watch window:-
    Test string:-*
    Content-Disposition: form-data; name="name"\n\nOmkar\n|
    In the above test string the last character is a pipe symbol.
    And the java code i have written is: -
    code:
        public static void getParameterValue(String paramName, String testParameter) {
                  String parameterRegex = "name=\""+paramName+"\"(.*)|";
                  Pattern pattern = Pattern.compile(parameterRegex,Pattern.DOTALL);
                  Matcher matcher = pattern.matcher(testParameter);
                  boolean isFound = matcher.find();
                  if (isFound) {
                       System.out.println("The parameter value is : "+matcher.group(1));
             }After, the debug line moves over the first line in this method, the value contained in the "parameterRegex" string variable is:-
    Regex:-*
    name="name"(.*)|
    However, my SOP statement, prints null....even though, "isFound" variable is true....can someone please explain me what could be the problem, where i am going wrong ?....
    I have even, set the DOTALL option for the regex.
    please some one help me!
    Thanks and Regards
    Omkar Patkar

    zomkar wrote:
    Sorry, folks, i did not mention the fact that i had posted the my query, in Java ranch also. But my problem lead to another problem of CROSS - POSTING !
    Apologies, for that !....but please, does any one have a solution to my regex ? .... any one ? please ?
    The value i get in paramaname is :- name
    which is present in double quotes in test string.
    is my regex incorrect ?The discussion at JavaRanch seems to be pretty alive, so why not leave this thread and continue there? That way, people won't have to first read two different threads on two different forums before trying to help you.

  • Problem with email regular expression

    I found the following regular expression from this website : http://www.regular-expressions.info/email.html
    \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\bor
    ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$I am using the following website to check its success, as well as my java app. : http://www.regexplanet.com/simple/index.html
    of course java has a problem with the illegal escape character so i add another "/".
    In both of my testing scenarios the regex value seems to fail. Am I missing something here?
    If anyone could also test this regex and verify or correct my problem I would be very grateful.
    Edited by: rico16135 on Jun 5, 2010 4:01 PM
    Edited by: rico16135 on Jun 5, 2010 4:02 PM

    rico16135 wrote:
    of course java has a problem with the illegal escape character so i add another "/".I seem to be missing the distinction between a forward slash / which is not an escape character, and a backslash \ which is.
    Also, if you show your actual Java code (in code tags, of course), and describe clearly and precisely what's going wrong--pasting in the exact, complete error message and indicating clearly which line caused it, if there is one--people will be in a better position to help you.

  • Problem with Regular Expression

    Hi There!!
    I have a problem with regular expression. I want to validate that one word and second word are same. For that I have written a regex
    Pattern p=Pattern.compile("([a-z][a-zA-Z]*)\\s\1");
    Matcher m=p.matcher("nikhil nikhil");
    boolean t=m.matches();
    if (t)
              System.out.println("There is a match");
         else
              System.out.println("There is no match");
    The result I am getting is always "There is no match
    Your timely help will be much appreciated.
    Regards

    Ram wrote:
    ErasP wrote:
    You are missing a backward slash in the regex
    Pattern p = Pattern.compile("([a-z][a-zA-Z]*)\\s\\1");
    But this will fail in this case.
    Matcher m = p.matcher("Nikhil Nikhil");It is the reason for that *[a-z]*.The OP had [a-z][a-zA-Z]* in his code, so presumably he know what that means and wants that String not to match.

  • Problem on regular expression

    Hello everyone,
    I am working on a project that require me to seperate the following examples:
    +0,+0.0000+E1,-4.33+E1,-4.222+E1,-6.33+E2,-6.55+E2
    What I need is the final four results seperately:
    -4.33+E1,
    -4.222+E1,
    -6.33_E2,
    -6.55+E2.
    I am totally fresh to regular expression. Any help is well appreciated!
    Thanks,
    +Kunsheng
    Solved!
    Go to Solution.

    Take a look at the code below.  It doesn't make much use of RegEx, but I think it is simpler.
    Message Edited by jmcbee on 03-05-2009 12:42 PM
    Message Edited by jmcbee on 03-05-2009 12:43 PM
    CLA, CLED, CTD,CPI, LabVIEW Champion
    Platinum Alliance Partner
    Senior Engineer
    Using LV 2013, 2012
    Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
    Attachments:
    Parse String.PNG ‏10 KB
    Parse String 80.vi ‏9 KB

  • Problem forming regular expression

    Hi,
    I want to use regular expression to match a repeating pattern until it meets a particular character. Eg.
    The string I am trying to match is a function definition.
    function abc()
    This is the pattern I am using to match the above string.
    Pattern p =
    Pattern.compile("function abc.*\r*\n*\\{(\r*\n*.*)*(\r\n)*\\}", Pattern.MULTILINE);
    "function abc" takes care of the method signature
    " .*\r*\n*\\{" takes care of all spaces/characters/newline till it encounters the opnening brace
    "(\r*\n*.*)*" this iswhere the problem lies. This matches all the individual new lines in the method body. But I dont want it to match the closing brace "}" . It is doing that currently. How can I avoid that? So that the next part of the pattern i.e. "\\}" actually matches the closing brace?

    DrLaszloJamf wrote:
    Isn't the basic difference between regular grammars and context free grammars? The latter can generate matched parens, the former can't?I guess you mean by "regular grammar" a "regular language" (forgive my ignorance if they are the same)? But yes, AFAIK that is a difference. However, there are regex engines that can cope with these recursive matches (an undefined number of back references). Perl is one of them.
    It is an often heard complaint about implementations of regular expression engines: they have grown too big for what they were created for.

  • Problems with regular expressions.

    Hi all.
    I want to substitute within an xml file a string with the following structure:
    Referencer="//@Model/@OwnedElement.0/@OwnedElement.1/@OwnedElement.0/@OwnedElement.1/@OwnedElement.33 ..."
    where the dots mean that the string within the quotes may be repeated (separated by spaces) many times.
    I've tried to match such expression with java regex, with no luck. I thought running
    line.contains("Referencer=\"[^\"\\r\\n]*\"");
    would return true, but it didn't.
    Could anybody point me the right way?.
    Thank you all in advance.

    Method String.contains() does not take a regular expression - you need to use method String.matches() or class Pattern.
    This looks to be a good problem to solve using http://elliotth.blogspot.com/2004/07/java-implementation-of-rubys-gsub.html .

Maybe you are looking for

  • Audio/Video slightly out of sync after exporting media and trying to watch on iPhone

    Hey adobe tech heads So, I recently upgraded to the new Adobe Premiere Pro CC, from Premiere Pro and I have to say that there doesnt seem to be any difference to the normal functionalites. While I am merely a beginner, i suppose there are more comple

  • Strange frames i can't get rid of

    I'm using premiere to cut an already cut movie. this means that most of my edits are close to a pre-existing cut. for some reason single frames are seen in the edits when i play it back, but not when i advance frame by frame. to make matters worse wh

  • Email notification to SMTP with Authentication

    Sending Email Notification: What tags do you add to ns_emails.xsl to configure it for an smtp server that requires authentication? I've tried many things but none of them have worked, I looked all over the oracle forum and found a user who posted the

  • Cannot control timeline

    I am a newbie using Flash MX Professional 2004. I am trying to create a pop-up menu. I am using the technique of having an invisble button with a hit area all but that of the submenu. Frame 9-11 is called "start" and has an action of stop(); When the

  • How Truecaller works???

    Apple says that they are not allowing any application to get incoming call number or not give permission  any application which is doing this. Then how Truecaller app works?? How it take incoming call number give us name of that number owner??