Home > Back-end >  Text Parse - Need to extract text after (E) lengh 17 char
Text Parse - Need to extract text after (E) lengh 17 char

Time:06-27

I need to extract the following text (KNAB3512BJT142015) but none of my formula works as my marker are brackets and mess with the formula

here the global text :

de la Collectivité, Paralegatio d RE (D.2.1) B3512 (E) KNAB3512BJT142015 (F.3) 2T070 (J.3) CI (P.6) 7

Thank you for your help

CodePudding user response:

var str = "de la Collectivité, Paralegatio d RE (D.2.1) B3512 (E) KNAB3512BJT142015 (F.3) 2T070 (J.3) CI (P.6) 7";
var from = "(E) "
var start = str.indexOf(from)   from.length;
var result = str.slice(start, start   17);
console.log(result)

CodePudding user response:

You need to escape brackets

const str = `de la Collectivité, Paralegatio d RE (D.2.1) B3512 (E) KNAB3512BJT142015 (F.3) 2T070 (J.3) CI (P.6) 7`

const re1 = /\(E\) (\w ) \(/; // grab until next space and left bracket
console.log(str.match(re1)[1])

const re2 = /\(E\) (\w{17}) \(/; // grab 17 chars after (E) pluse space
console.log(str.match(re2)[1])

console.log(str.split("(E)")[1].slice(1,18)); //split on (E) and take the next 17 after skipping the space

  • Related