in reply to Re: RegEx to filter \s not between labels
in thread RegEx to filter \s not between labels

Greetings I0,

++! That's amazingly cool code. I love one-liners like that. In my specific situation, I don't need the START/STOP markers removed, and I can't imagine a senario where the data string would contain nested labels, however... I'm still curious. How would the nested labels version look?

(Note that I did spend some time trying to figure this out for myself so I could at least post a few bits of code here for others to revise, but I've failed to figure out even the basic theory without going into many, many lines of basic code.)

-gryphon
code('Perl') || die;

  • Comment on Re: Re: RegEx to filter \s not between labels

Replies are listed 'Best First'.
Re: Re: Re: RegEx to filter \s not between labels
by I0 (Priest) on May 23, 2002 at 21:40 UTC
    #Okay, you asked for it:
    $_ = '0 1 STARTPRESERVE STARTPRESERVE 2 STOPPRESERVE STOPPRESERVE 3 4 STARTPRESERVE STARTPRESERVE 5 STOPPRESERVE STOPPRESERVE 6 7'; (my $re=$_)=~s/((STARTPRESERVE)|(STOPPRESERVE)|.)/${['(','']}[!$2]\Q$1 +\E${[')','']}[!$3]/gs; $re= join'|',map{quotemeta}eval{/$re/}; die $@ if $@ =~ /unmatched/; s/\s+|($re)/${[$1,' ']}[!$1]/g;