const regex = /(?<!\d{8})_(?!\d{6})/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<!\\d{8})_(?!\\d{6})', 'gm')
const str = `Patate_17890505_TitreEnCamelCase.ext
EPFL_AlgebreLineaire
TaxonomieProprietesFonctionsComplexes.v0.ipe.20210302_005606.pdf
1_
12_
_1
_12
12345678_
_123456
12345678_12345
1234567_123456
1234567_12345
123456_12345
12345678_1234567
123456789_123456
123456789_1234567
_patate__truc__
___
foo_12345678
foo_12345678_123456_bar
12345678_123456
foo12345678_123456bar`;
const subst = `.`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions