$re = '/(^\s+|\s*?(\r?\n)\s*|\s+$)/';
$str = ' 2002 Why Orwell Matters, Basic Books (US)/UK edition as Orwell\'s Victory, Allen Lane/The Penguin Press.
2005 Thomas Jefferson: Author of America. Eminent Lives/Atlas Books/HarperCollins Publishers, ISBN 0-06-059896-4
2006 Thomas Paine\'s "Rights of Man": A Biography. Books That Shook the World/Atlantic Books, ISBN 1-84354-513-6
2007 God Is Not Great: How Religion Poisons Everything. Twelve/Hachette Book Group USA/Warner Books, ISBN 0-446-57980-7 / Published in the UK as God Is Not Great: The Case Against Religion. Atlantic Books, ISBN 978-1-84354-586-6
2007 The Portable Atheist: Essential Readings for the Non-Believer. Perseus Publishing. ISBN 978-0-306-81608-6 (editor)
2010 Hitch-22 Some Confessions and Contradictions: A Memoir . Hachette Book Group. ISBN 978-0-446-54033-9 (published by Allen and Unwin in Australia in May 2010 with the shorter title: Hitch-22. A Memoir.) ISBN 978-1-74175-962-4
2012 Mortality. Atlantic.
Pamphlets
1971 Karl Marx and The Paris Commune. Sidgwick & Jackson Ltd. ISBN 0283484829
1990 The Monarchy: A Critique of Britain\'s Favourite Fetish. Chatto & Windus, 1990.
1995 The Missionary Position: Mother Teresa in Theory and Practice. Verso.
2003 A Long Short War: The Postponed Liberation of Iraq. Plume Books. Originally released as Regime Change (Penguin).
2011 The
';
$subst = "\2";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php