How do I get part of the string from the size of a word?

0

I want to take only the name of the subject of a h1 containing the following text: "ENF N1A METHODOLOGY OF SCIENTIFIC RESEARCH (MONTH)". In the case what interests me in this string is the value "METHODOLOGY OF THE CINENTÍFICA RESEARCH". The idea I had was to use regex to return this value by taking text from the set of strings that was greater than x. Can anyone tell if this is the best way?

[ADD]
The full names of the courses follow the following pattern:

[cod_dis)] [""] [class] [""] [name] "[(cod_filial)]

In this case, for the examples I cited, I marked in italics the part I would like to take from the whole:

ENF N1A METHODOLOGY OF SCIENTIFIC RESEARCH (MES)
ENF N1A APPLIED COMPUTERS (MONTH)
ENF N1A INSTRUMENTAL ENGLISH (MONTH)

It would look like this:

SCIENTIFIC RESEARCH METHODOLOGY
APPLIED COMPUTERS
ENGLISH INSTRUMENTAL

P.S. I know that before the discipline there is the code of the class that has a maximum of 4 characters, and after the discipline, there is the (cod_filial) that is always enclosed in parentheses.

    
asked by anonymous 16.04.2018 / 16:53

1 answer

4

Based on the reported patterns, a regex that can be used is /([^ ]{1,4} [^ ]{1,4} )([^(]+)( \([^)]+\))/g . Example:

var text = [
  'ENF N1A METODOLOGIA DA PESQUISA CIENTÍFICA (MES)',
  'ENF N1A INFORMÁTICA APLICADA (MES)',
  'ENF N1A INGLÊS INSTRUMENTAL (MES)'
];

var subtext = [];

for(var i = 0; i < text.length; i++) {
  var exec = /([^ ]{1,4} [^ ]{1,4} )([^(]+)( \([^)]+\))/g.exec(text[i]);
  subtext.push(exec ? exec[2] : null);
}

var $output = document.getElementById("output");

for(var i = 0; i < text.length; i++) {
  var $h1 = document.createElement('h2');
  $h1.innerHTML = text[i];
  $output.append($h1);
}

for(var i = 0; i < text.length; i++) {
  var p = document.createElement('p');
  p.innerHTML = subtext[i];
  $output.append(p);
}
<div id="output"></div>
    
16.04.2018 / 18:05