0

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.

manojlds
  • 290,304
  • 63
  • 469
  • 417
dattebayo
  • 2,012
  • 4
  • 30
  • 40

2 Answers2

1

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.

manojlds
  • 290,304
  • 63
  • 469
  • 417
0

You said:

The above expression matches, ABC: X=12,Y=1.79769313486232E+308". But it fails for "ABC: X=12,Y=1,79769313486232E+308"

Without any context, I'm not sure what the purpose of matching the above strings is, but I can see why it would be perfectly legitimate to match the first but not the second.

The format of 1.79769313486232E+308 is scientific notation for a very large number (the +308 basically means move the decimal point 308 places to the right). It is a legitimate number with the dot, but not with the comma.

It is true that some locales may use a comma as a decimal character rather than a dot, but scientific notation is standardised to use the dot, as are programming languages and other computer applications that would use numbers in this format, so it is legitimate to enforce it to be a dot and prevent the comma from being used.

To demonstrate why this is important, if the comma were to be allowed in this example, it would create an ambiguity as to where the value of Y ended, because comma is already being used to show the end of the value of X, using a comma instead of the point in Y could make a computer think that the value of Y is 1, which would be incorrect.

Spudley
  • 166,037
  • 39
  • 233
  • 307
  • I appreciate your reply. As you guessed right, the issue is with the locale. The spanish locale has ';' as list-separator so separating x value from y value is not an issue. – dattebayo Jun 06 '11 at 08:09