I'm trying to do a script who extract tags from a string
For that, i used RegExp
I simplified my code as much as possible.
var ereg = /(\[text\](.+)\[\/text\])+?/;
var str = '[text]MyText[/text][text]MyOtherText[/text]';
result = ereg.exec(str);
if (result) {
for (i = 0; i < result.length; i++) {
document.body.innerHTML += "<br>[" + i + "] => " + result[i];
}
}
Output:
[0] => [text]MyText[/text][text]MyOtherText[/text]
[1] => [text]MyText[/text][text]MyOtherText[/text]
[2] => MyText[/text][text]MyOtherText
My problem is that i want the variable result return me what is between the tags [text][/text], meaning 'MyText' et 'MyOtherText'.
Instead it returns me 'MyText ** [/ text] [text] MyOtherText **'.
How do I do this?
My regular expression is not non-greedy?