Frage

The Eclipse reservoir simulator takes ASCII data files as input. They have a way to compress saved data, so when inputting their saved data, they have to expand it like this:

4*0 4*1 0 3*1 5*0 1 0 2*1 10*.2
Expanded to
0 0 0 0 1 1 1 1 0 1 1 1 0 0 0 0 0 1 0 1 1 .2 .2 .2 .2 .2 .2 .2 .2 .2 .2

The times of repetition is any positive integer except 1, and the data could be any non-negative real number.

Given a string of compressed data, use regular expression to achieve expansion. What should I write in replace line? Would appreciate an example in UltraEdit; scripting / macros are accepted.

Original Regex:

   Find: (\d+)\*(\d)
Replace: 
War es hilfreich?

Lösung

This type of replacement requires a general string expression on the replacement side, and as far as I know, UltraEdit doesn't supply that with just the "Find/Replace With" interface. But you can write a script to do it:

UltraEdit.activeDocument.write( 
  UltraEdit.activeDocument.selection.replace(
    /(\d+)\*(\S+)/g,
    function(_, count, value) { 
      return new Array(count-0+1).join(value+' ').replace(/ $/,''); }
));
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top