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')
- you have a float
float_thing - you convert/cast it to string by
num2strwith 17 digit precision - you use regular-expression by
regexprepwhere you replace the stringstrwith the match[09]{3,}i.e. all characters of zeros and nines whose count is at least three, with the replacement0..0and9..9, respectively- the last part should be possible where you should use lookBehind possibly in the last part
Both answers works
Matlab version based on Stephane's answer and docs
% http://se.mathworks.com/help/matlab/matlab_prog/tokens-in-regular-expressions.html
p=1.0000000000000002; str=num2str(p,17); regexprep(str, '([09])\1{3,}' , '$1..$1')
% 1.0..02
p=0.9999999999999999; str=num2str(p,17); regexprep(str, '([09])\1{3,}' , '$1..$1')
% 0.9..989
System: Linux Ubuntu 16.04
Languages: Perl, Matlab, Unix, Bash, Python, ...
..characters in the output?