[Solved] Split a string between special characters [closed]


Use a regular expression with a capture group and RegEx.exec() to extract any substrings between three apostrophes. The pattern uses lazy matching (.*?) to match any sequence of characters (including none) between the apostrophes.

const str = " My random text '''tag1''' '''tag2''' ";
re = /'''(.*?)'''/g;
matches = [];

while (match = re.exec(str)) {
    matches.push(match[1]);
}

console.log(matches);

Output

[ 'tag1', 'tag2' ]

solved Split a string between special characters [closed]