Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Regex replace in context

by jkahn (Friar)
on Dec 11, 2002 at 18:39 UTC ( [id://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

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://219144]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found