Search code examples
.netregexregexbuddy

Regular expression question


In .NET 4.0 What does the reg ex,

"^ABC(: ([^=]+(?<! )=(?! )[^,]+(?<! )(,(?! )|$))+)?$"

matches to?

Some sample examples would be of much help.

I am quite surprised with following results. The above expression matches, "ABC: X=12,Y=1.79769313486232E+308". But it fails for "ABC: X=12,Y=1,79769313486232E+308". The only difference is the decimal symbol for the double number.

Thanks.


Solution

  • Look at the [^,] that basically says that after the = (=(?! )) match anything that doesn't have a , in it.

    The Regex is not really elegant:

    Even something like ABC would match. Something like ABC: X=1Y=1 would also match. I would say, don't use this and assemble a proper regex for what you need.