in reply to Re: Re: Regex help
in thread Regex help

What the good lord does that code do? Or rather, how does it work? Whats the $|||=1 bit, etc?

Replies are listed 'Best First'.
Re: Re: Re: Re: Regex help
by ysth (Canon) on Jan 30, 2004 at 09:30 UTC
    That bit is just charging up the magic wand. It can just as well be a separate statement:
    $| = 1; print grep --$|, /\b(\w+)\b(?=(.*?)\b\1\b)/g'
    To get even elements instead of odd elements, you just start with the magic wand in the other position:
    print grep --$|,($|&&=0)|| /\b(\w+)\b(?=(.*?)\b\1\b)/g'
    or:
    $| = 0; print grep --$|, /\b(\w+)\b(?=(.*?)\b\1\b)/g'
    Why ||= and &&= instead of = is left as an excercise for the reader. Hope that clears things up for you :)