Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Regex replace in context

by jkahn (Friar)
on Dec 11, 2002 at 18:39 UTC ( #219144=note: print w/replies, xml ) Need Help??

in reply to Regex replace in context

FWIW, it also means that $& does not include a.

I find the negative zero-width-lookbehind assertion rather handy (e.g. s/(?<!z)b/d/), which means, roughly, "substitute b for d whenever it's not preceded by z".

This trick reminds me of the reason we have \b -- sometimes a boundary condition can be met by no character at all, e.g., we'd like to match on both "b" and "ab".

In both cases, I've taken advantage of the not-modifying-$& effects in my code. I wish you could add the quantifiers, though, even though I can imagine just how complicated look-behinds with quantifiers might become...

jyust my $0.02,


Replies are listed 'Best First'.
Re: Re: Regex replace in context
by John M. Dlugosz (Monsignor) on Dec 11, 2002 at 21:32 UTC
    I suppose it would be clearer than (?<!(?i-x:pattern))

    Idle thought:

    sub import { shift; return unless @_; die "unknown import: @_" unless @_ == 1 and $_[0] eq ':constant'; overload::constant qr => sub { my $s= shift; $s =~ s/(<!\\)\x{ab}/(?:/g && $s =~ s/(<!\\)\x{bb}/)/g; return eval qr/$s/; }; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://219144]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2018-05-24 02:42 GMT
Find Nodes?
    Voting Booth?