Just like title says , code behind like
var re = /^\S(if\([\s\S]*?\)\s*?\{)([\s\S]*?)(\})(?:\s*?(else\s*?\{)([\s\S]*?)(\}))?/g;
var str = "@if(bool) { @{code} <div>@(var)</div>} else { @while(condition){ @{ } <div>@(var)</div>} <div>str</div> }"
//first time execute
re.test(str); //true
//second time execute
re.test(str); //false
//third time execute
re.test(str); //true
The even times I execute result is true , the odd times I execute is false .
The Situation Is I am building a front-end template engine , the razor style , I want it can parse code template like this
@if(some condition)
{
<div>@(some variable or sentence code)</div>
@for(var i = 0; i < 10 ; i ++)
{
<div>@(i)</div>
}
}
else
{
<div>bla bla ...</div>
}
So I need to use Regex to fetch the template part , but I account this problem now , looks weird ... any help or guide ,thanks ...