I have this JavaScript code:
var textareas = document.getElementsByTagName('textarea');
var content = textareas[0].value;
var reg = new RegExp(/^.*[[]#.+#[]].*$/mgi);
var res = content.match(reg); // always null
The content var contains a long multiline string that contains patterns like [#some text goes here#]. I tested the regex with some online testing tools and it works against the string. Using the regex in JavaScript fails though – any idea why?
Thanks!
How about this?
On execution,
rescontains the string'[#some text goes here#]'.Note that I have escaped
[and]. If they are not escaped, anything enclosed within them forms a character class.