Re: Force POSIX NFA in Perl?



Ivan Fomichev wrote:

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.


.



Relevant Pages

  • Re: Regex Usage, or use Substring?
    ... Is Regex more efficient than manually comparing values using Substring? ... Well, let's start off by getting rid of the unnecessary substrings, ... when you're only looking at a single character: ... but it looks okay to inspection... ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: perl one liner to remove all but the base file name
    ... Oxnard wrote on MMMMCMIII September MCMXCIII in ... && how can I get to just 'file' using a regex. ... Also I have thought about using basename with the suffix but the ...
    (comp.lang.perl.misc)
  • Re: perl one liner to remove all but the base file name
    ... && how can I get to just 'file' using a regex. ... Also I have thought about using basename with the suffix ... I cannot find a reference to it. ...
    (comp.lang.perl.misc)
  • Regex
    ... I am trying to form a regex to search my string and give me substrings ... split the string at every occurence of hyphen - character but not if a ...
    (microsoft.public.dotnet.languages.csharp)
  • perl one liner to remove all but the base file name
    ... how can I get to just 'file' using a regex. ... extension. ... Also I have thought about using basename with the suffix but the ...
    (comp.lang.perl.misc)