Regular Expressions in CS5.5 - something is wrong

Hello Everybody,
Please correct me, but I think, I found a serious problem with regular Expressions in Indesign CS5.5 (and possibly in other apps from CS5.5).
Let's start with simple example:
var range = "a-a,a,a-a,a";
var regEx = /(a+-a+|a+)(,(a+-a+|a+))*/;
alert( "Match:" +regEx.test(range)+"\nLeftContext: "+RegExp.leftContext+"\nRightContext: "+RegExp.rightContext );
What I expected was true match and the left  and the right context should be empty. In Indesign CS3 that is correct BUT NOT in CS5.5.
In CS 5.5 it seems that the only first "a-a" is matched and the rest is return as the rightContext - looks like big change (if not parsing error in RegExp engine).
Please correct me if I am wrong.
The second example - how to freeze ID CS5.5:
var range = "a-a,a,a-a,a";
var regEx = /(a+-a+|a+)(,(a+-a+|a+)){8,}/;
alert( "Match:" +regEx.test(range)+"\nLeftContext: "+RegExp.leftContext+"\nRightContext: "+RegExp.rightContext );
As you can see it differs only with the {8,} part instead of *
Run it in CS5.5 and you will see that the ID hangs (in CS3 of course it runs flawlessly}.
The third example - how to freeze ID 5.5 in one line (I posted it earlier in Photoshop forum because similiar problem was called earlier):
alert((/(n|s)? /gmi).test('s') );
As you can guess - it freezes the CS5.5 (CS3 passes the test).
Please correct me if I am doing something wrong or it's the problem of Adobe.
Best regards,
Daniel Brylak

Hi Daniel,
Thanks for sharing. Really annoying indeed.
Just to complete your diagnosis, what you describe about CS.5 is the same in CS5, while CS4 behaves as CS3.
var range = "aaaaa";
var regEx = /(a+-a+|a+)(,(a+-a+|a+))*/;
alert([
    "Match:" +regEx.test(range),
    "LeftContext: "+RegExp.leftContext.toSource(),        // => CS3/4: EMPTY -- CS5+: EMPTY
    "RightContext: "+RegExp.rightContext.toSource()        // => CS3/4: EMPTY -- CS5+: ",a,a-a,a"
    ].join('\r'));
So there is a serious implementation problem of the RegExp object from ExtendScript CS5.
I don't think it's related to the greedy modes. By default, JS RegExp quantifiers are greedy, and /a*/ still entirely captures "aaaaaa" in CS5+.
By the way, you can make any quantifier non-greedy by adding ? after the quantifier, e.g.: /a*?/, /a+?/, etc.
I guess that Adobe ExtendScript has a generic issue in updating the RegExp.lastIndex property in certain contexts—see http://forums.adobe.com/message/3719879#3719879 —which could explain several bugs such as the Negative Class bug —see http://forums.adobe.com/message/3510078#3510078 — or the problems you are mentioning today.
@+
Marc

Similar Messages

  • Regular expression for excluding something

    Hi,
    I am using Java to implement a parser and I got a problem with a regular expression.
    I want to fetch some file names such as "blabla.txt", "blabla.doc" but not "blabla.jpg".
    I started with
    Now my problem is how to filter out "blabla.jpg".
    Any ideas are welcome.
    Pengyou

    pengyou wrote:
    I did not test it in Java (I have no my java tester right now) but I belive that if it is fine then it should be fine with the on-line tester: http://www.regular-expressions.info/javascriptexample.html
    Could you also test against that tester?No! Why should I? This is a Java forum and I assume you will be using it with Java so why should I waste time testing it outside Java.
    Edited by: sabre150 on Dec 16, 2009 1:06 PM
    I took pity on you and tested in on that site. It works as expected and excludes file names ending in jpg.

  • Index.php "Something is wrong with the XAMPP installation :-("

    Hello Brian Woods, Dave Powers, and Other Experts.
    I am new on the block as far as Wordpress and trying to run a testing server using XAMPP via Dreamweaver CS5.  I carefully followed all the directions in your tutorials:
    http://www.adobe.com/devnet/dreamweaver/articles/setup_testing_server.html
    http://www.adobe.com/devnet/dreamweaver/articles/dw_wordpress_pt2.html
    Brian, everything worked up until I reached the following step under the topic of: "Testing code hinting"
    After I open the "index.php" file, I received the following error in Dreamweaver CS5:
    "Something is wrong with the XAMPP installation :-("
    Again, I carefully followed all the instructions and everything up until now works:  the Theme loads up fine, XAMPP works, and I can view the control panel fine in Wordpress.
    Does anyone have any ideas?
    Thanks for your support.
    DELL INSPIRON LAPTOP CORE 2 64 BIT 2.0 GHZ
    4 GIG RAM
    WINDOWS 7 PREMIUM

    Steak&Lobster wrote:
    After I open the "index.php" file, I received the following error in Dreamweaver CS5:
    "Something is wrong with the XAMPP installation :-("
    That's a new one on me, but I very much doubt that the error message was generated by Dreamweaver, because DW is designed to work with any testing server. It's not tied to using XAMPP. Sounds like some weirdness from XAMPP. I must say that XAMPP 1.7.4 seems to have a few bugs.

  • Working w/ regular expressions

    Hi all,
    I'm having trouble figuring out what regular expression to use to parse my output. I want to capture a block of text that starts with a tab (\t) and ends with a line containing the word "error code."
    For example, if my output is the following: ( [\tab] denotes ASCII tab character)
    [\tab]Some command
    Anytext
    Anytext
    blah blah error code is 0
    [\tab]Some other command
    [\tab]Yet another command
    Anytext
    blah blah error code is 1
    I would like subsequent calls to matcher.find() to find these two blocks:
    [\tab]Some command
    Anytext
    Anytext
    blah blah error code is 0
    and
    [\tab]Yet another command
    Anytext
    blah blah error code is 1
    I thought the regular expression should be something like
    "[\t](.*\n)+.*error code.*"
    but the above regular expression returns the entire text intead of the two "blocks" that I want. I know that Java returns the longest match for the expression but I don't know how to exclude "error code" in the middle...
    "[\t](.*\n)+(.*error code.*){1}" ???
    Any help is greatly appreciated.
    Thanks,
    KK

    ..but I'm not sure what is the purpose of the second part (?:\\n|\\Z).
    Would someone care to explain this too me?This non-capturing group is for final delimiter, it means "last character is a Line Feed char or end of input reached", just to prevent error if last line is an error line without Line Feed char.
    A good reference about groups are at JRegex documentation/examples:
    http://jregex.sourceforge.net/.
    Good news for you: the minimal regular expression that solves your problem.
    import java.io.*;
    import java.util.*;
    import java.util.regex.*;
    public class ParseTest {
    public static void main(String[] args) throws Exception {
    String Output =
    "\t\tgcc -someoption file0\n"
    + "\t\tgcc -someoption file1\n"
    + "\t\tgcc -someoption file2\n"
    + "\t\tgcc -someoption file3\n"
    + "some error message\n"
    + "some more error message\n"
    + "make: 1254-004 The error code from the last command is 1.\n"
    + "make: 1254-005 Ignored error code 1 from last command.\n"
    + "\t\tgcc -someoption file4\n"
    + "\t\tgcc -someoption file5\n"
    + "error message\n"
    + "more error message\n"
    + "make: 1254-004 The error code from the last command is 1.\n"
    + "make: 1254-005 Ignored error code 1 from last command.\n"
    + "\t\tgcc -someoption file6\n"
    + "\t\tgcc -someoption file7\n"
    + "last error message\n"
    + "make: 1254-005 Ignored error code 1 from last command.";
    System.out.println(Output+"\n");
    final String
    // Regular Expression pattern to find only commands with error messages.
    // $1 = command
    // $2 = error message
    re = "\\t+(.+)\\n([^\\t]+[^\\t\\n])(?:\\n|$)";
    Pattern p = Pattern.compile(re);
    System.out.println("Pattern:\n"+p.pattern());
    Matcher m = p.matcher(Output);
    for (int j=1; m.find(); j++) {
    System.out.println("\nMatching "+j+":\n");
    System.out.println("--------------------------------");
    System.out.println(m.group(1));
    System.out.println("--------------------------------");
    System.out.println(m.group(2));
    System.out.println("--------------------------------");
    Regards.

  • What's wrong with the regular expression?

    Hi all,
    For the life of me I can not figure out what is wrong with this regular expression
    .*\bA specific phrase\.\b.*
    This is just an example the actual phrase can be an specific phrase. My problem comes when the specific phrase ends in a period. I've escaped the period but it still gives me an error. The only time I don't get an error is when I take off the end boundry character which will not suffice as a solution. I need to be able to capture all the text before and after said phrase. If the phrase doesn't have a period it would look like this...
    .*\bA specific phrase\b.*
    which works fine. So what is it about the \.\b combination that is not matching?
    I've been banging my head on this for a while and I'm getting nowhere.
    The application highlights text that comes from a server. The user builds custom highlights that have some options. Highlight entire line, match partial word, and ignore case. The code that builds my pattern is here
    String strHighlight = _strHighlight;
            strHighlight = strHighlight.replaceAll("\\*", "\\\\*");
            strHighlight = strHighlight.replaceAll("\\.", "\\\\.");
            String strPattern = strHighlight;
            if(_bEntireParagraph)
                if(_bPartialWord)
                    strPattern = ".*" + strHighlight + ".*";
                else               
                    strPattern = ".*\\b" + strHighlight + "\\b.*";           
            else
                if(_bPartialWord)
                    strPattern = strHighlight;
                else               
                    strPattern = "\\b" + strHighlight + "\\b";  
            if(_bIgnoreCase)
                _patHighlight = Pattern.compile(strPattern, Pattern.CASE_INSENSITIVE);
            else
                _patHighlight = Pattern.compile(strPattern);So for example I matching the phrase: The dog ate the cat. And that phrase came over in the following text: Look there's a dog. The dog ate the cat. "Oh my!"
    And my user has the entire line and ignore case options selected then my regex woud look like this: .*\bThe dog ate the cat\b.*
    That should get highlighted, but for some reason it doesn't. Correct me if I'm wrong but doesn't the regex read as follows:
    any characters
    word boundry
    The dog ate the cat[period]
    word boundry
    any characters until newline.
    Any help will be much appreciated

    A word boundary (in the context of regexes) is a position that is either followed by a word character and not preceded by one (start of word) or preceded by a word character and not followed by one (end of word). A word character is defined as a letter, a digit, or an underscore. Since a period is not a word character, the only way the position following it could be a word boundary is if the next character is a letter, digit or underscore. But a sentence-ending period is always followed by whitespace, if anything, so it makes no sense to look for a word boundary there. I think, instead of \b, you should use negative lookarounds, like so:   strPattern = ".*(?<!\\w)" + strHighlight + "(?!\\w).*";

  • Is my regular expression wrong?

    Hi,
    I have a string (5+4-6*7/8) which I need to separate into
    Digits and Operators.I am using regular expressions for this.
    Here's my code.
    String s = "(5+4-6*7/8)";
    String delim = "(/+-*)";
    Pattern Digit = Pattern.compile("[0-9]");
    // Create a regular expression which will match only digits.
    Pattern LeftParen = Pattern.compile("[(]");
    // Create a regular expression which will match only Left Parenthesis.
    Matcher m; //Create a Matcher instance
    StringTokenizer st = new StringTokenizer(s,delim,true);
    n = st.countTokens();
    while (st.hasMoreTokens())
    t = st.nextToken();
    // Match the string token t with the Digit Pattern.
    m = Digit.matcher(t);
    if(m.matches())
    // if condition is true,then its a digit.Hence push it on number stack "sn".
    sn.push(t);
    m.reset();
    m = LeftParen.matcher(t);
    // Match the string token t with the Left Parenthesis Pattern.
    if(m.matches())
    // If condition is true,then its a left parenthesis.Hence push it on operator stack "so".
    so.push(t);
    prec=0;
    new_prec=0;
    }//End of while loop
    After this my number stack "sn" is having only digit values,which is fine.
    But my operator stack "so" does not contain any elements viz (.+,-,*,/,).
    What's wrong in my code?
    Thanks,
    -Prashant.

    First of all, unless you only ever plan on having single digit numbers in your program, the RE for numbers is wrong. I believe that it should be [0-9]*
    Secondly, brackets are used for groupings, e.g. [a-z][0-9] so you don't need them for your open parenthesis. Third, since parenthesis are operators in RE, you probably want to escape your parenthesis:
    Pattern LeftParen = Pattern.compile("\(")

  • Those darn regular expressions again ...

    Greetings,
    I feel reluctant to ask this question because I sincerely hate regular expressions, but here is a regular expression question:
    Suppose I receive a byte stream from a device: after having received a, say, 'X' byte some more bytes follow, followed by a number: two or three digits followedby a dot and then some more digits follow. I am interested in that number so I cooked up this:
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class Test {
         public static void main(String[] args) {
              Pattern pat= Pattern.compile("X.*(\\d{2,3}\\.\\d*)");
              String  str= "fooXbar123.456baz";
              Matcher mat= pat.matcher(str);
              if (mat.find())
                   System.out.println(str.substring(mat.start(1), mat.end(1)));
    }The regular expression represents what I want to see: a capital X, some bytes and the number. b.t.w. I convert those bytes to chars so there is no problem there. The output of this little snippet is "23.456", i.e. it takes the shortest variant of group #1 (the '1' is eaten by the "dot-star" subexpression.
    I hope you understand why I hate those regular expressions so much; they're the devil's invention. My question boils down to: how can I find the longest variant of that group #1 expression? i.e. "123.456".
    A bit more info: the 'bar' part can contain almost anything, including digits. It can even be totally empty. The capital 'X' has to be present and "bar" doesn't contain a capital 'X'.
    kind regards,
    Jos

    JosAH wrote:
    Never did get my head round the 'pimping lemon'!If a word x y z t u is in a language L and if x y^n z t^n u is also in that language the pumping lemma applies and L is a context free language; that is so trivial ... ;-)Was that a low flying jet or just the 'pimping lemon' going straight over my head!
    >
    I used to teach APL to non-(scientists/engineers/mathematicians) . One of the most unsatisfying jobs ever. I love APL but how do you teach APL to someone who does not understand matrices? How do you teach APL to someone who expects 1-1-1-1-1 to be -3? I still get agencies contacting me about APL jobs even though I last used it 25 years ago!I used to program APL on an old DEC LA/36 paper terminal. You had to lean over backwards because those APL symbols were printed on the front side of the keys. Therefore my knees blocked the paper feed so all my printouts turned into a mess ...I was lucky. I used an IBM (5110 springs to mind but at my age!) box and some IBM terminals attached to an IBM370. No silly paper tape. It just cost a fortune for every second one was connected to the IBM370.
    >
    How's the 'limp' Jos? Any better?Not really; I put too much strength on my left leg (the 'good' one) and my body thought something was wrong so it started a bad inflamation in that leg. I'm on inflamation suppressing pills now. dammit.
    We are a real pair of crocks! I mixed and laid 6 ton of concrete and disposed of 8 ton of hardcore during Dec, Jan and Feb. My knee is swollen like a balloon and I'm on anti-inflammatory pills right now. BUT I have to eat a full meal before taking them and that means I have to have to take more pills to suppress my excess stomach acid. God I wish I was 50 again!
    I shall have to visit Holland sometime before we are both confined to wheelchairs.

  • Pattern matching regular expressions

    I'm attempting to determine if a string matches a pattern of containing less than 100 alphanumeric characters a-z or 0-9 case insensitive. So my regular expression string looks like:
    "^[a-zA-Z0-9]{0,100}$"And I use something like...
    Pattern pattern = Pattern.compile( regexString );I'd like to modify my regex string to include the email 'at' symbol "@". So that the at symbol will be allowed. But my understanding of regex is very limited. How do I include an "or at symbol" in my regex expression?
    Thanks for your help.

    * Code by sabre150
    private static final Pattern emailMatcher;
        static
            // Build up the regular expression according to RFC821
            // http://www.ietf.org/rfc/rfc0821.txt
            // <x> ::= any one of the 128 ASCII characters (no exceptions)
            String x_ = "\u0000-\u007f";
            // <special> ::= "<" | ">" | "(" | ")" | "[" | "]" | "\" | "."
            //              | "," | ";" | ":" | "@"  """ | the control
            //              characters (ASCII codes 0 through 31 inclusive and
            //              127)
            String special_ = "<>()\\[\\]\\\\\\.,;:@\"\u0000-\u001f\u007f";
            // <c> ::= any one of the 128 ASCII characters, but not any
            //             <special> or <SP>
            String c_ = "[" + x_ + "&&" + "[^" + special_ + "]&&[^ ]]";
            // <char> ::= <c> | "\" <x>
            String char_ = "(?:" + c_ + "|\\\\[" + x_ + "])";
            // <string> ::= <char> | <char> <string>
            String string_ = char_ + "+";
            // <dot-string> ::= <string> | <string> "." <dot-string>
            String dot_string_ = string_ + "(?:\\." + string_ + ")*";
            // <q> ::= any one of the 128 ASCII characters except <CR>,
            //               <LF>, quote ("), or backslash (\)
            String q_ = "["+x_+"$$[^\r\n\"\\\\]]";
            // <qtext> ::=  "\" <x> | "\" <x> <qtext> | <q> | <q> <qtext>
            String qtext_ = "(?:\\\\[" + x_ + "]|" + q_ + ")+";
            // <quoted-string> ::=  """ <qtext> """
            String quoted_string_ = "\"" + qtext_ + "\"";
            // <local-part> ::= <dot-string> | <quoted-string>
            String local_part_ = "(?:(?:" + dot_string_ + ")|(?:" + quoted_string_ + "))";
            // <a> ::= any one of the 52 alphabetic characters A through Z
            //              in upper case and a through z in lower case
            String a_ = "[a-zA-Z]";
            // <d> ::= any one of the ten digits 0 through 9
            String d_ = "[0-9]";
            // <let-dig> ::= <a> | <d>
            String let_dig_ = "[" + a_ + d_ + "]";
            // <let-dig-hyp> ::= <a> | <d> | "-"
            String let_dig_hyp_ = "[-" + a_ + d_ + "]";
            // <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
            // String ldh_str_ = let_dig_hyp_ + "+";
            // RFC821 looks wrong since the production "<name> ::= <a> <ldh-str> <let-dig>"
            // forces a name to have at least 3 characters and country codes such as
            // uk,ca etc would be illegal! I shall change this to make the
            // second term of <name> optional by make a zero length ldh-str allowable.
            String ldh_str_ = let_dig_hyp_ + "*";
            // <name> ::= <a> <ldh-str> <let-dig>
            String name_ = "(?:" + a_ + ldh_str_ + let_dig_ + ")";
            // <number> ::= <d> | <d> <number>
            String number_ = d_ + "+";
            // <snum> ::= one, two, or three digits representing a decimal
            //              integer value in the range 0 through 255
            String snum_ = "(?:[01]?[0-9]{2}|2[0-4][0-9]|25[0-5])";
            // <dotnum> ::= <snum> "." <snum> "." <snum> "." <snum>
            String dotnum_ = snum_ + "(?:\\." + snum_ + "){3}"; // + Dotted quad
            // <element> ::= <name> | "#" <number> | "[" <dotnum> "]"
            String element_ = "(?:" + name_ + "|#" + number_ + "|\\[" + dotnum_ + "\\])";
            // <domain> ::=  <element> | <element> "." <domain>
            String domain_ = element_ + "(?:\\." + element_ + ")*";
            // <mailbox> ::= <local-part> "@" <domain>
            String mailbox_ = local_part_ + "@" + domain_;
            emailMatcher = Pattern.compile(mailbox_);
            System.out.println("Email address regex = " + emailMatcher);
        }Wow. Sheesh, sabre150 that's pretty impressive. I like it for two reasons. First it avoids some false negatives that I would have gotten using the regex I mentioned. Like, [email protected] is a valid email address which my regex pattern has rejected and yours accepts. It's unusual but it's valid. And second I like the way you have compartmentalized each rule so that changes, if any custom changes are desired, are easier to make. Like if I want to specifically aim for a particular domain for whatever reason. And you've commented it so that it is easier to read, for someone like myself who knows almost nothing about regex.
    Thanks, Good stuff!

  • Using Regular Expressions to replace Quotes in Strings

    I am writing a program that generates Java files and there are Strings that are used that contain Quotes. I want to use regular expressions to replace " with \" when it is written to the file. The code I was trying to use was:
    String temp = "\"Hello\" i am a \"variable\"";
    temp = temp.replaceAll("\"","\\\\\"");
    however, this does not work and when i print out the code to the file the resulting code appears as:
    String someVar = ""Hello" i am a "variable"";
    and not as:
    String someVar = "\"Hello\" i am a \"variable\"";
    I am assumming my regular expression is wrong. If it is, could someone explain to me how to fix it so that it will work?
    Thanks in advance.

    Thanks, appearently I'm just doing something weird that I just need to look at a little bit harder.

  • Regular Expression Rage.

    Hello,
    I'm currently being driven insane by the regular expressions in java. I want to use the matches(String aString) method of String to find out if the user has inputed a wilcard filename such as *.txt or *.bmp etc.
    The problem is I can't seem to put a * or . into the expression without it being considered as a special character. I want to match *. followed by one or more characters. It would seem logical that this should be "\*\..*" however the compiler complains that \* and \. are ilegal escape characters. In the API "\{" is given as an example of an escape character but when I try it I get the same compiler error.
    Also I was trying to match a single backslash which I thought should be "\\" This compiles okay but when I run the program I get runtime error from Pattern. More confusingly if I use ".*\\.*" it will match with any input.
    Am I doing something fundamentally wrong ? Some of my other matching patterns seem to work just fine.

    Well, for the Java compiler you need to escape \ making it \\.
    Additionally the regexp requires you to escape \, so you escape it once for the regexp engine and once for the Java compiler making it \\\\.

  • Trouble with tribbles, i mean regular expressions

    Hi all
    im trying to make a regular expression that finds all the comments in a given string
    stuff like this
    /* this is my comment */
    then what i want to do is to remove all those found comments from the string and leave me with the original string without any comments.
    anyway i know i need a pattern but i cant get my pattern right, this is what i have at the moment
    Pattern remComment = Pattern.compile(" ^\\*?[\\w\\s\\W]+?*\\ ", Pattern.DOTALL | Pattern.MULTILINE);
    can anyone help me and let me know where im going wrong
    im basically trying to say any thing that starts with \* <any other text here> until a *\
    thanks

    There is something else wrong, I just tryied:
    * Comments.java
    * version 1.0
    * 07/06/2005
    package samples;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    * @author notivago
    public class Comments {
         * @param args
        public static void main(String[] args) {
            String comment =
                "/*\r\n" +
                "does this do it won\r\n" +
                "*/\r\n" +
                ".activegrouptab\r\n" +
                "{\r\n" +
                "white-space:nowrap;\r\n" +
                "border-top-width:1pt;\r\n" +
                "cursor:hand;\r\n" +
                "}\r\n" +
                "/*\r\n" +
                "does this do it too\r\n" +
                "*/\r\n" +
                ".activegrouptabdisabled\r\n" +
                "{\r\n" +
                "font-family:verdana;\r\n" +
                "font-size:7pt;\r\n" +
                "}\r\n" +
                "/*\r\n" +
                "does this do it free\r\n" +
                "*/\r\n" +
                ".activesectiontab\r\n" +
                "{\r\n" +
                "width:90%;\r\n" +
                "background-image:url(hocbt.gif);\r\n" +
                "overflow:auto;\r\n" +
                "color:#ffffff;\r\n" +
            Pattern remComment = Pattern.compile("/\\*.*?\\*/", Pattern.DOTALL | Pattern.MULTILINE);
            Matcher matcher = remComment.matcher(comment);
            while( matcher.find() ) {            
                System.out.println( "The comment: \n" + matcher.group() );
                System.out.println("----");
    }with the output:
    The comment:
    does this do it won
    The comment:
    does this do it too
    The comment:
    does this do it free
    ----

  • Item Validation using Regular Expression

    Hi,
    I am trying to apply a Validation to a text field item, with the type as Regular Expression.
    The text input into the field should be in a HH:MM:SS format, ie 05:30:00 (for 5:30am).
    The text I am placing in the 'Validation Expression 2' box is:
    [0-2][0-9]\:[0-5][0-9]\:[0-5][0-9]
    This doesn't seem to work and I get an error message when I enter text in the correct format.
    I have even tried to use other comparisons, for example:
    or
    .{8}
    but these still give me an error message.
    Anyone have any ideas?

    Thanks for your help Flavio, the Regular Expression tool is really helpful.
    When I use this tool to compare strings with my regular expression, I get output = TRUE, which means I'm getting it right, but for some reason when I copy the same Regular Expression syntax into APEX, it doesn't work.
    I try to input correct strings into the field that is validated by the Reg Expr, but it still gives me an error.
    It seems to be something I am doing wrong within the application, but I can't figure out what I'm missing.
    I am creating an Item Level Validation with details:
    Type: Regular Expression
    Validation Expression 1: P23_BUS_DAY_COVERAGE_START
    Validation Expression 2: ^(([0-1][0-9])|(2[0-3])):[0-5][0-9]:[0-5][0-9]$
    Has anyone had similar problems using regualr expression validation in APEX?

  • Want to replace a string containing consecutive repeating  words to one using regular expression

    Hi Experts,
    I need a regular expression to replace all duplicate words in a string with one.
    eg: 'Hello Hello World 4-4-5 etc etc' should be changed to 'Hello World 4-4-5 etc'.
    I tried many of them but they had one or the other problem. like (\w+\S\W)\1+' replace with ' \1' and  ' (\w+\W)\1+' replaced with ' \1' , etc
    Thanks in advance
    Tarique

    Hi,
    Translating what frank said to JAVA would be something like this:
            StringBuffer result = new StringBuffer();
            String myString = "This is right right, that is wrong.";
            String[] words = myString.split(" ");
            String lastWord = "";
            for (String str : words){
                if (!str.contains(lastWord))
                    result.append(str);
                else
                    result.append(str.substring((lastWord.length() >= 0 ? lastWord.length() : 0 ) , str.length()));
                lastWord = str;
                result.append(" ");
            System.out.println(result);
    If you didnt have points and commas in your message then would be easier. But the code is not 100% correct and you will need to make it work according to yours requirements.

  • Dumbfounded by Scanner processing String using regular expression

    I was reading Bruce Eckel's book when I came across something interesting: extending Scanner with regular expressions. Unfortunately, I was confronted with an issue that doesn't make much sense to me: if the String that I am scanning contains a hyphen, the Scanner doesn't produce anything. As soon as I take it out, it all works like a charm. Here is my example:
    import java.util.Scanner;
    import java.util.regex.*;
    public class StringScan {
    public static void main (String [] args){
         String input = "there's one caveat when scanning with regular expressions";
         Scanner scanner = new Scanner (input);
         String pattern = "[a-z]\\w+";
         while (scanner.hasNext(pattern)){
              scanner.next(pattern);
              MatchResult match = scanner.match();
              String output = match.group();
              System.out.println(output);
    }What could be the reason? I imagined it could be because the hyphen for some reason gets given a special meaning but when I tried escaping it, it still didn't work.

    Thanks for your prompt reply.
    I have figured out what was wrong with my code, by the way. Since a single quote is not a word character, it does not match w+. And as the very first input token does not match, the scanner stops immediately. I rewrote my regex to "[a-z].*" and now it does work.

  • Regular expressions for URLs to match extensions

    I am working on a simple method that will assign a specific extension
    (e.g. ".jsp", ".php", ".cfm", etc.) to the end of a URL if it doesn't
    find anything marking a valid extension, however, I do not want to add
    an extension if one is found.
    Consider my code:
    import java.util.regex.Pattern;
    public static final String urlEndSlashPattern = "/?";
    public static final String urlQSPattern = "\\??([a-zA-Z0-9\\-_\\.]
    +=[^&]*&?)*";
    public static final String urlAnchorPattern = "#[^#]*$";
    public static void addExtToUrl(String url, String myExt, String[]
    exts) {
       StringBuffer sb = new StringBuffer();
       boolean hasExt = false;
       for (int i = 0; i < exts.length; i++) {
    sb.append(".").append(exts).append(urlEndSlashPattern).append(urlQSPatte�rn).append(urlAnchorPattern);
    if (Pattern.matches(sb.toString(), url)) {
    hasExt = true;
    sb = new StringBuffer();
    if (!hasExt) {
    url += "." + myExt;
    The issue I want to bring up is the regular expression pattern I'm
    using appears to fail.  I want to check and see if the URL I provide
    ends with a valid extension, followed by optional "/" or a query
    string or an anchor or any combination of these.
    Like say if I have
    http://www.blah.com/index.html
    Then don't add the ".jsp" extension
    But if I have
    http://www.blah.com/registration/
    Then I *want* to add the ".jsp" extension:
    http://www.blah.com/registration.jsp
    Or if I have:
    http://www.blah.com/registration/?foo=bar#baz
    Then it needs to change to
    http://www.blah.com/registration.jsp?foo=bar#baz
    But if I have
    http://www.blah.com/registration/index.php?foo=bar#baz
    Then I do *not* add the ".jsp" extension.
    Hope that makes sense now.  Bottom line is that the pattern above
    doesn't seem to work.  Ideas?
    Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Ok, just for fun, let's try it.
    URL: http://www.blah.com/?bar=baz#anchor
    Absolutely valid URL and something possible (remember, Balus, this is from a database entry, thus, it can be anything at all!)
    Let's split onto the last /
    Your last entry will be
    ?bar=baz#anchor
    So if I re-insert the .jsp that it would not find I get
    http://www.blah.com/.jsp?bar=baz#anchor
    INVALID URL
    Now let's try this one, BalusC:
    http://www.blah.com/index.jsp?forwardURL=http://www.wee.com/gotcha_balus/
    Now we split according to the ... last /
    http://www.blah.com/index.jsp?forwardURL=http://www.wee.com/gotcha_balus.jsp
    Valid URL, but possibly wrong when the query string value for "forwardURL" is read, thus, making the URL ultimately wrong.
    Two examples that show that splitting by the last / can't work here.

Maybe you are looking for

  • Why can't I get a downloaded purchased movie to play?

    I bought the film, "Woodstock," a couple of years ago thru iTunes. I see the film listed in iTunes and I see the actual file on my computer, but I cannot get it to play. It has played in the past. I was going to re-download thru iCloud, but it says i

  • Oracle BPM requirement

    Hi all, I have a requirement in Oracle BPM 12c that I want to know how I can achieve that. Suppose I have a hierarchy of three users i) Initiator ------------------>>> ii) Manager ---------------------->>> iii) Director Initiator submit a request and

  • Can anuone help me on persistence API problem please?

    I would like someone to explain me why when using persistence API sometime i can insert data in database normally but later when i have added more functionalities like ajax, and file upload i can insert data in database using persistence API. for ins

  • Profit Center in Create PO w/o Account Assignment Category

    Hi SAP Experts, Still related to my previous post re: display of the Profit Center field in the PO create screen without Account Assignment Category.  Have looked into the SAP HELP ECC 6.0 on why is it not part of the "Maintain AAC" but to no avail.

  • QT 7.03 still no go

    I was hoping that QT 7.03 would solve the problems introduced in version 7.02. So far all the problems (stuttering H264 and DivX playback, frameskips of more than 10 sec.) still persist. This is rather disappointing and makes me believe that Apple sh