Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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,

--jeremy


Comment on Re: Regex replace in context
Select or Download Code
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/; }; }
    —John

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://219144]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2015-07-07 22:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls