in reply to experimental regex (?(?{code}) conditional (??{ 'code' }) )

If you have a token like this, then regex is not the right tool. Use tr to count < and > and just see if they are equal in number.
#!/usr/bin/perl -w use strict; for ( '<1>', # want match '<<2>>', # want match '<<3>', # want fail '<<<4>>', # want fail '<<5>>>>', # want fail ) { my $left = tr/<//; my $right = tr/>//; if ($left == $right) { print "$_ match\n"; } else { print "$_ fail\n"; } } __END__ Prints: <1> match <<2>> match <<3> fail <<<4>> fail <<5>>>> fail

Replies are listed 'Best First'.
Re^2: experimental regex (?(?{code}) conditional (??{ 'code' }) )
by Anonymous Monk on Nov 12, 2010 at 16:53 UTC
    If you have a token like this, then regex is not the right tool.

    Sure, but perl regex definitely is the right tool for the job.

    FYI, the topic at hand is perl experimental feature (?(?:{code}) (??{'code'})), stick to it :)

      Can you some give examples that illustrate your point better? Meaning the need for more complex syntax, ie where more straightforward approaches fail to deliver the desired result?