% ^ \s* ( # <1> < \s* ([a-zA-Z:]+) # <2/> (?: \s*[a-zA-Z:]* \s* = \s* (?:'[^']*'|"[^"]*") )* \s* (/\s*)? # <3/> > (?:[^<>]* | (?1))* (?(3)| <\s*/\s*\2\s*> ) ) # \s* $ %x #### # Match # No match # Match * # No match # No match # No match # Match < fooo / > # Match foo # No match foo # No match foo # Match foo # Match * # Match * This one matches as well * (wow)

Host:
User:
Pass:
Login

This single regex can actually test XML well-formedness :) (Doesn't take and etc, though)