I need to compare a string with a regular expression that contains square brackets in itself.
eg. If I test() a regExp ("^[b]", "i") with string "[b]Bold Text[/b]", it should return true. But its returning false due to square brackets.
How can I solve this?
[code=javascript]var txt = "[b]Page starts[/b]";
function matchTag(start) {
var regStart = new RegExp("^["+start+"]", "i");
if (regStart.test( txt))
alert ('Matching');
}[/code]
eg. If I test() a regExp ("^[b]", "i") with string "[b]Bold Text[/b]", it should return true. But its returning false due to square brackets.
How can I solve this?
[code=javascript]var txt = "[b]Page starts[/b]";
function matchTag(start) {
var regStart = new RegExp("^["+start+"]", "i");
if (regStart.test( txt))
alert ('Matching');
}[/code]
Comment