0

I'm trying to pick out sub-strings marked up between flags (using % as flags). It should also avoid sections marked up between another flag (using & for the second flag).

&Label 1&%A lot of text goes in here, but this is the part I want to pick out as a match, it needs to include characters such as __**underline and asterisk**__ and also be able to handle \n line breaks.%&Label 2&%This would become the second match. We also want to include symbols such as and other emotes.%

I want this to result in two matches:

  1. A lot of text goes in here, but this is the part I want to pick out as a match, it needs to include characters such as __**underline and asterisk**__ and also be able to handle \n line breaks.
  2. This would become the second match. We also want to include symbols such as and other emotes.

I've tried:

/(?<=%)[^&].*?(?=%)/g <- Works on https://regex101.com/ but not in my own java script

    getFieldLabels: function(text){
        let regexp = /(?<=&)[a-zA-Z\s]*(?=&)/g;
        let array = [...text.matchAll(regexp)];
        return array;
    },

/(%(.*)\%)/g <- Requires a rowbreak in the string to work

0 Answers0