in reply to Regex logic

You did "until an H" instead of "until the first H". Fix:
X[^XH]*H[^HD]*D

By the way, the non greedy modifier is deceptively complex and you'll have better luck by avoiding it.