in reply to New regex trick...

What's the mnemonic for \K?

Update: Ah, got it.

This is sort of like Prolog's "cut", isn't it? Match a prefix, then never backtrack back past the \K anchor to satisfy the regex. Can you have multiple \Ks in a single regex? I can see Abigail-II having lots of fun with this.

--
The hell with paco, vote for Erudil!
:wq

Replies are listed 'Best First'.
Re: Re: New regex trick...
by japhy (Canon) on Jul 22, 2002 at 19:40 UTC
    Yes, you can have multiple \K's in a regex, although only the last one really means anything, should the regex succeed. I'm actually curious why you would need more than one in the same branch, but it's perfectly legal.

    But no, it's not cut. Cut is (?>pat). This is just telling the regex engine to pretend it just started matching, that $& is defined starting HERE.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Re: Re: New regex trick...
by japhy (Canon) on Jul 22, 2002 at 19:22 UTC
    There are two. K = Keep, as in, "keep everything we've just matched", because I envision it being used in substitutions. The other mnemonic is "\K isn't used by anything yet". ;)

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;