Does Perl support conditional regular expression :
(?(condition)true-pattern|false-pattern)
i.e. if the condition is true then try to match the true pattern else try to match the false pattern
If Perl supported conditional regular expressions then why didn’t this code print 1?
use strict;
use warnings;
$_ = 'AB';
if ( /(?(A)B|C)/ ) {
print 1;
}
Perl supports conditional patterns.
Your regex doesn’t just not match, it throws the following syntax error:
That’s because
Ais not a valid condition.