Skip to main content
6 of 7
deleted 1 character in body

How to Do This LookBehind in Regex?

Data: 1.000000000000002, 0.999999999999999
Expected output: 1.0..02, 0.9..9 where you can replace .. with any other shorthand for cut
Pseudocode in Matlab

float_thing=1.0000000000000002; % 0.999999999999999 
str=num2str(float_thing,17);
regexprep(str, '[09]{3,}' , 'SOME_lookBehind_thing_here for 0..0/9..9')
  1. you have a float float_thing
  2. you convert/cast it to string by num2str with 17 digit precision
  3. you use regular-expression by regexprep where you replace the string str with the match [09]{3,} i.e. all characters of zeros and nines whose count is at least three, with the replacement 0..0 and 9..9, respectively
    • the last part should be possible where you should use lookBehind possibly in the last part

System: Linux Ubuntu 16.04
Languages: Perl, Matlab, Unix, Bash, Python, ...