in reply to Simple string parsing help with regex

Use negative look-behind assertion (documented in perlre):
s%(?<!<)/%%g
No if needed.

Replies are listed 'Best First'.
Re^2: Simple string parsing help with regex
by cavac (Prior) on Dec 22, 2011 at 16:11 UTC

    "Negative look-behind"? This is (except for the name) a rather cool feature i just now learned. I'd give you more than one "++", but i'm not allowed to...

    BREW /very/strong/coffee HTTP/1.1
    Host: goodmorning.example.com
    
    418 I'm a teapot
Re^2: Simple string parsing help with regex
by shadowfox (Beadle) on Dec 22, 2011 at 15:10 UTC
    Now that is very cool, I can see using that a lot! Somwhow I've never ran across that ability before, despite skimming pealre countless times.

    Thanks very much!
Re^2: Simple string parsing help with regex
by aaron_baugher (Curate) on Dec 23, 2011 at 23:43 UTC

    The various new look-ahead/behind assertions from 5.10 are very cool, but I'll admit I haven't used them enough to find them handy yet, so in a case like this, I still think, "I want to get rid of every slash that follows a character other than a less-than, so I'll capture that character and replace them both with it," leading to this:

    s|([^<])/|$1|g;

    However, I just benchmarked that compared to your look-behind method, and yours is 75% faster. Guess I need to start learning those newer assertions, and not just for when it's impossible to do something the old way!

    Aaron B.
    My Woefully Neglected Blog, where I occasionally mention Perl.