Force POSIX NFA in Perl?

Discussion in 'Perl Misc' started by Ivan Fomichev, Jul 15, 2005.

  1. 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.
    Ivan Fomichev, Jul 15, 2005
    #1
    1. Advertising

  2. 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.
    Brian McCauley, Jul 15, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RN
    Replies:
    0
    Views:
    2,538
  2. r

    NFA to DFA

    r, Jan 12, 2004, in forum: C++
    Replies:
    6
    Views:
    10,184
    Donovan Rebbechi
    Jan 14, 2004
  3. angelayoub
    Replies:
    1
    Views:
    3,614
    Victor Bazarov
    Feb 5, 2004
  4. Ricky

    NFA to DFA

    Ricky, Jan 12, 2004, in forum: C Programming
    Replies:
    2
    Views:
    4,099
    Mark McIntyre
    Jan 12, 2004
  5. Willing 2 Learn

    Help w/ converting FSA to NFA program

    Willing 2 Learn, Mar 9, 2006, in forum: C++
    Replies:
    1
    Views:
    304
    osmium
    Mar 9, 2006
Loading...

Share This Page