i'm not that familiar with javascript. i'm trying to do something very simple which works fine on my local, but doesn't seem to work on a 3rd party environment (Google tag manager - macro)...
- I'm trying to match 'hello world' inside the var, 'code'
- then strip out any white space, to include carriage returns, new line breaks, etc.
- i think the issue could be somewhere around these two lines (as a check of str comes back as an object on my local, but null on the 3rd party environment)
- when I debug further on my local, the value inside 'str[1]' is true and a string, and as expected would show up as empty on the 3rd part env
here's my code,
Am i doing something wrong? is there a more efficient way to do this, guaranteed to work within any JavaScript environment?
- I'm trying to match 'hello world' inside the var, 'code'
- then strip out any white space, to include carriage returns, new line breaks, etc.
- i think the issue could be somewhere around these two lines (as a check of str comes back as an object on my local, but null on the 3rd party environment)
Code:
var patt = /<h2 class="pic">My message<\/h2>(.*?)<\/div>/ig;
var str = patt.exec(code);
here's my code,
Code:
function (){
var code = '<h2 class="pic">My message</h2>hello world</div>';
var patt = /<h2 class="pic">My message<\/h2>(.*?)<\/div>/ig;
var str = patt.exec(code);
var result = str[1].replace(/^\s+|\s+$/ig,"");
return result;
}
Am i doing something wrong? is there a more efficient way to do this, guaranteed to work within any JavaScript environment?