in reply to regex using negative look ahead assertion

This is better handled with XPath.

m( <pg [^>]* > # A <pg> tag with optional body ( # Capture START (?: # Skip past all the non-tag-beginng-like things but be sure # not to allow backtracking. (?> [^<]+ ) | # OR # Match something like a tag beginning as long as it # isn't an opening for <pg < (?! pg\s ) ) ) # Capture END </pg> )x;