1

Good afternoon community:

I would like to obtain an array from the following expression, I want to use two delimiting parameters that vary according to my need, so that the its a substring is obtained but if it finds parameters in this substring identical to the delimiters it does not affect the substring.

Is somewhat similar to grouping signs but with strings.

For this case, the delimiting parameters are the this BEGIN END

For example I have next string:

"Is a testing 
  BEGIN extract third 
    BEGIN  extract second 
      BEGIN extract first expression END
    expresión END
   expresión END
Thank you very much"

This array I would like to obtains as follows:

[
   "extract first expression",//substring More Internal
   "extract second BEGIN extract first expression END expression",//Second...
   "extract third BEGIN extract second BEGIN extract first expression END expression END expression"//....
    ]

I've seen these post Regular expression to get a string between two strings in Javascript and Get Substring between two characters using javascript

var str = 'Is a testing BEGIN extract third BEGIN extract second BEGIN extract first expression END expresión END expresión END Thank you very much';     
console.log(str.split('(').pop().split(')'));

and I also tryed

var str = 'Is a testing BEGIN extract third BEGIN extract second BEGIN extract first expression END expresión END expresión END Thank you very much';    

function testString($string,$textBefore,$textAfter) 
{ 
   var regExString = new RegExp("(?:"+$textBefore+")((.[\\s\\S]*))(?:"+$textAfter+")", "ig"); 
   var testRE = regExString.exec($string); 
   if (testRE && testRE.length > 1) 
   {   
     return testRE; 
   } 
} 
$all = testString(str,"(",")");
for(var i = 0; i < $all.length; i++){
    console.log($all[i]);
}

But they don't give me the expected results

Colo Colo
  • 11
  • 3

0 Answers0