Force POSIX NFA in Perl?

I

Ivan Fomichev

Hello, All!

I need to make Perl regex engine search over all possibilities to make
my '(?{})'
constructions work properly. It could be done by putting something like
'$(?{$match=1})(?<!$)' at the end of a regex. But it looks ugly and
annoys me.
The perfect solution would be switching on POSIX NFA lexically. Is it
possible?

WBR,
Ivan.
 
B

Brian McCauley

Ivan said:
I need to make Perl regex engine search over all possibilities to make
my '(?{})'
constructions work properly. It could be done by putting something like
'$(?{$match=1})(?<!$)' at the end of a regex. But it looks ugly and
annoys me.

Well the conventional 'always false' assertion is simply (?!) which is
marginally less ugly than (?<!$).

Appart from that you can of course put the suffix in a variable.

my $nfa = qr/(?{$match=1})(?!)/;

or write a subroutine

sub nfa {
local our $match;
my $suffix = qr/(?{$match=1})(?!)/;
$_[0] =~ /$_[1]$suffix/;
$match;
}

{
local our @substrings;
nfa 'ABC' => qr/(.+?)(?{ push @substrings => $1})/;
print "@substrings\n";
}
The perfect solution would be switching on POSIX NFA lexically.

Seems overkill to add yet another a feature to core Perl when it can be
achieved relatively simply already.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top