Skip to content Skip to sidebar Skip to footer

Ignore Regex Capturing Group When Using Javascript Split

I'm trying to split up a string into an array, and I'm looking to get back an array with the following format: ['a','b', 'c'] const code = '/*_ ex1.js */a/*_ ex2.js */b/*_ ex3.js *

Solution 1:

Try using String.prototype.match() with RegExp/[a-z](?=\/|\n|$)/g to match character class a through z followed by / character or newline character or end of input

const code = "/*_ ex1.js */a/*_ ex2.js */b/*_ ex3.js */c\n"
             + "/*_ ex4.js */d/*_ ex5.js */e/*_ ex6.js */f";
var res = code.match(/[a-z](?=\/|\n|$)/g);
console.log(res);

Post a Comment for "Ignore Regex Capturing Group When Using Javascript Split"