Good question Michael. Several writers have been given credit, but the originator was John Greenleaf Whittier.... from an 1856 poem, "Maud Muller". And it is a very good poem.
For of all sad words of tongue or pen,
The saddest are these: "It might have been!"