javascript - Why isn't the following regex removing the ## characters? -
(var = 0; < 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
second 1 outputs:
<p><a href="#toc-1">## chapter 1</a></p>
but should output instead:
<p><a href="#toc-1">chapter 1</a></p>
what doing wrong?
you didn't use regex correctly search google on how use regex in javascript learn that. btw don't need regex that. here fix:
tree[i].replace('##', '') + '</a></p>'
Comments
Post a Comment