I'm trying to get the regex for this value:
<5fond[3.4,550],[5.4,6.4,7.4, 8.4, 32.4],[ 9.4, 239.8662]
The numbers (minus the second one which appears to just be an integer) can be any decimal value.
I have tried the following but it doesn't seem to work.
private static readonly Regex RegexExp = new Regex(@"<5fond\[[0-9]*\.[0-9] ,[0-9]*\.[0-9] ],\[[0-9]*\.[0-9] ,[0-9]*\.[0-9] ,[0-9]*\.[0-9] ,[0-9]*\.[0-9] \],\[[0-9]*\.[0-9] ,[0-9]*\.[0-9] \]", RegexOptions.IgnorePatternWhitespace);
Any idea what I might be doing wrong?
CodePudding user response:
You can use
<5fond\[\s*\d*\.?\d (?:,\s*\d*\.?\d )*\s*](?:,\s*\[\s*\d*\.?\d (?:,\s*\d*\.?\d )*\s*])*
See the regex demo. Details:
<5fond\[
- a<5fond[
string\s*
- zero or more whitespaces\d*\.?\d
- an int/float number pattern(?:,\s*\d*\.?\d )*
- zero or more sequences of a comma, zero or more whitespaces, an int/float number\s*
- zero or more whitespaces]
- a]
char(?:,\s*\[\s*\d*\.?\d (?:,\s*\d*\.?\d )*])*
- zero or more occurrences of,
- a comma\s*\[\s*
- a[
char enclosed with zero or more whitespaces\d*\.?\d (?:,\s*\d*\.?\d )*
- an int/float and then zero or more occurrences of a comma, zero or more whitespaces, an int/float number]
- a]
char.