Hi,
I'm having difficulty throwing away the bits of the expression I don't want, and keeping the bits I do.
The problem is - given the input string:
{if cond}foo{else}bar{/if}
I'd like just to have:
0: {if cond}foo{else}bar{/if}
1: cond
2: foo
3: bar
And for the input string:
{if cond}foo{/if}
I'd like just to have:
0: {if cond}foo{else}bar{/if}
1: cond
2: foo
3:
The regex I've got at present looks like this:
\{if ([a-z0-9]+)\}([^\{]*?)(((?:\{else\})?)(.*?)?)\{/if\}
I get the following data back:
0: {if cond}foo{else}bar{/if}
1: cond
2:
3: foo{else}bar
4:
5: foo{else}bar
Which would require further parsing of the foo{else}bar
bit to get the respective values.
Is my regex anywhere near close?
I'm not too concerned about the sort of data this might be run over - including {
in the body of an if statement is allowed to break the regex. The values of foo
and bar
can be anything that does not include a {
.
Thanks,
Dom