i need to replace all [counter] occurences in a javascript variable. I have no idea why i don't get it working because when i use an online regexp tool like https://regex101.com/ , it matches the [counter]-occurences i want.
Example string to replace in:
<div id="ITEM-9" data-widget-id="9" data-widget-type="CounterWidget" data-counter="6" data-icon="fa fa-bell" data-filterid="2" data-hidewhenzero="1" data-countervalue="[counter]" class="cust-masonry-item col-xs-6 col-sm-4 col-md-3 col-lg-3 cust-masonry-item-height-1 ng-scope" style="position: absolute; left: 74.9035%; top: 0px;"><div class="cust-masonry-item-content"><div class="cust-dashboard-counter"><span class="cust-dashboard-counter-icon"><span class="fa fa-bell"></span></span><span class="cust-dashboard-counter-title cust-readable-text">API</span><span class="cust-dashboard-counter-count"><span class="cust-dashboard-counter-number">[counter]</span><span class="cust-dashboard-counter-subscript cust-readable-text"> Log messages to read</span></span></div></div></div>
And i try to replace the [counter]-strings with the word 'replaced' like this:
var newHTML = element[0].outerHTML.toString().replace('/(\[counter\])/g', 'replaced');
Expected outcome:
<div id="ITEM-9" data-widget-id="9" data-widget-type="CounterWidget" data-counter="6" data-icon="fa fa-bell" data-filterid="2" data-hidewhenzero="1" data-countervalue="replaced" class="cust-masonry-item col-xs-6 col-sm-4 col-md-3 col-lg-3 cust-masonry-item-height-1 ng-scope" style="position: absolute; left: 74.9035%; top: 0px;"><div class="cust-masonry-item-content"><div class="cust-dashboard-counter"><span class="cust-dashboard-counter-icon"><span class="fa fa-bell"></span></span><span class="cust-dashboard-counter-title cust-readable-text">API</span><span class="cust-dashboard-counter-count"><span class="cust-dashboard-counter-number">replaced</span><span class="cust-dashboard-counter-subscript cust-readable-text"> Log messages to read</span></span></div></div></div>
Yes, i am sure that the outerHTML contains the above string, however my words are not replaced.
I feel so dumb right now... Thanks for pointing me in the right direction.