Reverse a regex in javascript ?
function reverse(s) { return s.split('').reverse().join(''); } function reverseSequence (s) { // chopper les expression conditionnelles // et construire un tableau pour les stocker var conditionals1 = s.match(/\[(.*?)\]/g); var conditionals2 = s.match(/(\[(.+)\])+\{(.*?)\}/g); var conditionals3 = s.match(/[A-Z\.]{1}\{(.*?)\}/g); var conditionals4 = s.match(/\^(.)/g); // on reverse la sequence brutalement s = reverse(s); // on replace les expressions conditionnelles if(conditionals3) for(let i=0; i<conditionals3.length; i++) { s = s.replace(reverse(conditionals3[i]), conditionals3[i]); } if(conditionals2) for(let i=0; i<conditionals2.length; i++) { s = s.replace(reverse(conditionals2[i]), conditionals2[i]); } if(conditionals1) for(let i=0; i<conditionals1.length; i++) { s = s.replace(reverse(conditionals1[i]), conditionals1[i]); } if(conditionals4) for(let i=0; i<conditionals4.length; i++) { s = s.replace(reverse(conditionals4[i]), conditionals4[i]); } return s; } proteine = "[AVGIL]{0,5}K^U.[DE]"; reverseSequence(proteine); >> "[DE].^UK[AVGIL]{0,5}"
Latest posts by Fab (see all)
- La Horde du Contrevent : review - 13 October 2024
- For Whom the Bells Tolls: review - 4 August 2024
- Self Aware On Air Neon Sign - 8 June 2024