function test(content)
{
var expr = new RegExp('(<!-- IF ["a-zA-Z0-9_.!=<>\\s]+ -->[\\s\\S]*?)+' +
'(<!-- ELSE IF ["a-zA-Z0-9_.!=<>\\s]+ -->[\\s\\S]*?)?' +
'(<!-- ELSEIF ["a-zA-Z0-9_.!=<>\\s]+ -->[\\s\\S]*?)?' +
'(<!-- ELSE -->[\\s\\S]*?)?'
+ '<!-- ENDIF -->', 'im');
var results = expr.exec(content);
var incr = 0;
while (results != null && ++incr < 50)
{
console.log(results[0]);
var i, len, code = '';
for (i = 1, len = results.length; i < len; i++)
{
var statement = results[i];
if (typeof statement !== 'undefined')
{
// position for splitting into condition and output
var position = statement.indexOf('-->');
var condition = statement.substr(4, position - 5).trim().replace('AND', '&&').replace('OR', '||').replace('ELSEIF', 'else if')
var output = statement.substr(position + 3).trim();
var conditionElseIf = condition.substr(0, 7).toLowerCase() === 'else if';
var conditionElse = condition.substr(0, 4).toLowerCase() === 'else';
position = conditionElseIf ? 7 : condition.indexOf(' ');
var operation = position === -1 ? '' : condition.substr(position).trim();
// there is no lookbehind in JS, so also fetch char in front of regexp
var variablesExpr = new RegExp('(["a-z0-9_\-]+)(?!")', 'gi');
var variables = variablesExpr.exec(operation)
var zzz = 0;
while (variables !== null && ++zzz < 10)
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.