How to skip a column?

I have a text table:

13.5 0.12557 0.04243 -0.0073 0.00377 14 0.12573 0.05 -0.00697 0.00437 14.5 0.12623 0.05823 -0.00703 0.005 15 0.12853 0.0686 -0.00627 0.00493 15.5 0.1299 0.08073 -0.00533 0.0063 

where I would like to combine all the numbers except those that are listed in the first column. I tried using a negative lookbehind without success:

 (?<!^)[\dE-]+ 

How to combine all numbers except those indicated in the first column (13.5, 14, 14.5, 15, 15.5)?

+5
source share
1 answer

Please note that if you do not need data validation, you can do without a regular expression:

 var results = line.Split(new[] {"\r", "\n"}, StringSplitOptions.RemoveEmptyEntries) .Select(v => v.Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries).Skip(1)) .SelectMany(x => x); Console.WriteLine(string.Join(",",results)); // => 0.12557,0.04243,-0.0073,0.00377,0.12573,0.05,-0.00697,0.00437,0.12623,0.05823,-0.00703,0.005,0.12853,0.0686,-0.00627,0.00493,0.1299,0.08073,-0.00533,0.0063 

If you need only those numbers when the data is numbers, you can use

  var results2 = Regex.Matches(line, @"(?m)(?<!^[\p{Zs}\t]*)(?<=[\p{Zs}\t])-?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?") .Cast<Match>() .Select(m => m.Value); 

See C # demo .

The regular expression -?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)? float / integer number is explained here .

Template Details

  • (?m) is a multi-line modifier that makes ^ match the beginning of a line
  • (?<!^[\p{Zs}\t]*) is a negative lookbehind that does not match if there is a beginning of a line followed by horizontal + + space characters after it is immediately to the left of the current location
  • (?<=[\p{Zs}\t]) is a positive lookbehind that requires a horizontal space before
  • -?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)? - integer / floating point number:
    • -? - optional - char
    • [0-9]* - numbers 0+
    • \.? - optional . char
    • [0-9]+ - 1 + digits
    • (?:[eE][-+]?[0-9]+)? - optional sequence:
      • [eE] - a e or e char
      • [-+]? - optional - or + char
      • [0-9]+ - 1 + digits.
+2
source

Source: https://habr.com/ru/post/1274949/


All Articles