{%for 1 to depth %}    {%/for%}static NSRegularExpression *regex = nil;
{%for 1 to depth %}    {%/for%}if (!regex) {
{%for 1 to depth %}    {%/for%}    NSError *err = nil;
{%for 1 to depth %}    {%/for%}    regex = [[NSRegularExpression regularExpressionWithPattern:@"{{pattern}}" options:NSRegularExpressionCaseInsensitive error:&err] retain];
{%for 1 to depth %}    {%/for%}    if (!regex) {
{%for 1 to depth %}    {%/for%}        if (err) NSLog(@"%@", err);
{%for 1 to depth %}    {%/for%}    }
{%for 1 to depth %}    {%/for%}}
{%for 1 to depth %}    {%/for%}
{%for 1 to depth %}    {%/for%}NSString *str = LS(1);
{%for 1 to depth %}    {%/for%}
{%for 1 to depth %}    {%/for%}if ({%if predicate %}{{predicate}} && ({%/if%}[regex numberOfMatchesInString:str options:0 range:NSMakeRange(0, [str length])]{%if predicate %}){%/if%}) {
{%for 1 to depth %}    {%/for%}    [self match:TOKEN_KIND_BUILTIN_ANY discard:{%if discard %}YES{%else%}NO{%/if%}];
{%for 1 to depth %}    {%/for%}} else {
{%for 1 to depth %}    {%/for%}    [self raise:@"pattern test failed in {{methodName}}"];
{%for 1 to depth %}    {%/for%}}
