locked
Even number of quotes RRS feed

  • Question

  • Hello,

    can someone tell me why the phantastic regular expression:
    ^([^"]*|"[^"]*"[^"]*)*$
    matches the string:

    Test "der Suchen" nach den "ganzen Parametern" dieses Textes

    But doesn t come to an result (endless loop?) for the following string:

    Test "der Suchen" nach den "ganzen P"arametern" dieses Textes

    The regular Expression just looks, if the string contains a even number of quotes (") or not.
    If its even i want to get a true, else a false.
    It works for short strings quiet well, but i cannot find out why it doesn t work for the example above. I have to cancel the thread there.

    Thanks for your help in advance.

    Greets


    Thursday, September 4, 2008 1:34 PM

All replies

  • The expression is not causing an endless loop, it is causing an exponetially longer execution for a failed pattern.  The time increases exponentially with the number of non-quote characters and number of pair quotes.  It takes about 15-20 seconds to run on my machine.

    You have a pattern that resembles the classic exponential growth pattern in the article Regex Hangs My Expression.
    Les Potter, Xalnix Corporation, Yet Another C# Blog
    Thursday, September 4, 2008 2:44 PM