Root word is capitalized. Root word is a date. Hyphenate to avoid ambiguity. Root consists of two words. Root and prefix share identical letters. Prefix stands alone. Prefix is ex- or quasi-.Root Word Capitalized
un-American post-Keynesian pre-Roe eraRoot Word Is a Date
pre-1945 post-1960sAvoid Ambiguity
re-cover (not recover) un-ionized (not unionized) pre-judicial career (not prejudicial career) re-create (not recreate)Root Consists of Two Words
pre-Civil War days non-English-speaking visitors (Retain hyphen in English-speaking.)Identical Letters
co-owner anti-intellectual non-native post-trial reengineer (Patent lawyers routinely omit the hyphen.) reexamination (Ditto.)Prefix Stands Alone
macro- and microeconomicsPrefix Is ex- or quasi-
pre- and posttrial strategies or pre- and post-trial strategies (optional hyphen under the shared-letter rule)
Note: As a matter of style, it's best to use former instead of the prefix ex-.
Thus: former mayor.