I'm very new to js and programming, and i'd appreciate some help.
Suppose I have the following array (It is a single element array, they are not seperate elements)
var array =
[
'Foo\n' +
'bar23123\n' +
'barbarfoo\n' +
'foo, bar foo\n' +
'foo\n' +
'\n' +
'\n' +
'Bar\n' +
'\n' +
'\n'
]
Assuming there are multiple elements in the array, how can I write a regex expression to count and match the number of literal '\n' in between Foo\n and Bar\n in each element.
I wrote a partial solution to iterate through and return the count of all \n but how do I narrow my search to only return the values in between the two strings?
Here is the code:
let slashN = [];
for(let slash of array){
var reg = RegExp('\\n' , 'g')
slashN.push(slash.match(reg).length)
}
console.log(slashN);
I get the correct count, but I want to refine the regex expression.
Any help is highly appreciated.