javascript - group capturing multiple times behind stable prefix -


is possible create regex retrieves capturing groups matching type of html input:

<em>word1</em> <em>word2</em> <em>word3</em> prefix: <em>word4</em> <em>word5</em> <em>word6</em> <em>word7</em> 

that matches

word4 word5 

i have tried lookahead , lookbehind zero-length assertions no success.

here try

https://regex101.com/r/la9xa3/2

but know how make groups repeating on every next occurence following 'prefix: '

thanks lot,

julien

you need line begins prefix , texts inside <em> tags.

this better done in 2 passes in order not compromise performance , readability:

var re = /^prefix:((?: *<em>\w*\d*<\/em>)*) */gm;   var str = 'prefix: <em>word1</em> <em>word2</em> <em>word3</em>\n<em>word4</em> <em>word5</em>\nprefix: <em>word6</em> <em>word7</em> <em>word8</em>';  var arr = [];     while ((m = re.exec(str)) !== null) {    var tmp = m[1].match(/[^<>]*(?=<\/em)/g); // matches inside em    if (tmp) {                                // if there      tmp = tmp.filter(boolean);              // remove empty array elements      (var i=0; i<tmp.length;i++) {        arr.push(tmp[i]);                     // add resulting array      }    }  }  document.body.innerhtml = "<pre>" + json.stringify(arr, 0, 4) + "</pre>";


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -