in reply to Re: Conditional regex
in thread Conditional regex

I see your point but it's a regex question.

Replies are listed 'Best First'.
Re^3: Conditional regex
by ikegami (Patriarch) on May 08, 2009 at 20:27 UTC

    Not really. Like you said so well, your real problem is

    I am parsing a webpage right now to make it 508 compliant. If an IMG tag has an alt element, I need to leave it alone but if it doesn't, it needs one added

    I see writing an regexp-based parser as your (broken) solution, not your problem. I'm not gonna make a lot of work for myself reinventing an HTML parser when I can skip that step and go straight to changing the HTML you want changed.

Re^3: Conditional regex
by Your Mother (Archbishop) on May 08, 2009 at 20:26 UTC

    You could do some nested matching to make this "work" with regular expressions, as you were trying above but it is the wrong way to solve the problem for two reasons: it's as difficult as the related parser code and unless you're Jeffrey Friedl, it will never work as well as the related parser code.