Reputation: 55273
for (var i = 0; i < tree.length; ++i) {
if (tree[i].match(/^##/g)) {
console.log(tree[i])
tree[i] = '<p><a href="#toc-' + tocIndex++ + '">' +
tree[i].replace('/^## /gm', '') +
'</a></p>'
console.log(tree[i])
tocItems.push(tree[i])
}
}
The first console.log(tree[i])
outputs ## Chapter 1
The second one outputs:
<p><a href="#toc-1">## Chapter 1</a></p>
But it should output instead:
<p><a href="#toc-1">Chapter 1</a></p>
What am I doing wrong?
Upvotes: 0
Views: 33
Reputation: 1537
You didn't use regex correctly search google on how to use regex in javascript to learn that. btw you don't need regex to do that. here is the fix:
tree[i].replace('##', '') + '</a></p>'
Upvotes: 2