# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(\(\)\n[[:space:]]{1,}\{)|(\(\)[[:space:]]{1,}\{)"
test_str = ("// feedback thread\n\n"
"import java.util.*;\n\n"
"class Main\n"
"{\n"
" static Scanner scan = new Scanner(System.in);\n"
" static String deadEnd = \"dead end--morphing backwards!\";\n"
" static String gettingCloser = \"You'r getting closer\";\n"
" \n"
" // call this method after each decision has been made\n"
" public static void clearScreen() {\n"
" Scanner scan = new Scanner(System.in);\n"
" System.out.println(\"Press enter to continue.\");\n"
" String x = scan.nextLine(); \n"
" System.out.print(\"\\033[H\\033[2J\"); \n"
" System.out.flush(); \n"
" } \n\n\n\n"
" public static void decisionZero()\n"
" {\n"
" System.out.println(\"Decision Point 0\");\n"
" System.out.println(\"Choose a direction Mr. Mouse\");\n"
" String direction = scan.nextLine();\n"
" switch (direction.toLowerCase()) {\n"
" case \"n\":\n"
" System.out.println(\"You chose north.\");\n"
" System.out.println(deadEnd);\n"
" decisionZero();\n"
" break;\n\n"
" case \"s\":\n"
" System.out.println(\"You chose south.\");\n"
" System.out.println(gettingCloser);\n"
" decisionOne();\n"
" break;\n"
" \n"
" case \"e\":\n"
" System.out.println(\"You chose east.\");\n"
" System.out.println(deadEnd);\n"
" decisionZero();\n"
" break;\n\n"
" case \"w\":\n"
" System.out.println(\"You chose west.\");\n"
" System.out.println(deadEnd);\n"
" decisionZero();\n"
" break;\n"
" \n"
" }\n"
" }\n"
" \n"
" public static void decisionOne()\n"
" {\n"
" System.out.println(\"Decision Point 1\");\n"
" System.out.println(\"Choose a direction Mr. Mouse\");\n"
" String direction = scan.nextLine();\n"
" switch (direction.toLowerCase()) {\n"
" case \"n\":\n"
" System.out.println(\"You chose north.\");\n"
" System.out.println(deadEnd);\n"
" decisionZero();\n"
" break;\n\n"
" case \"s\":\n"
" System.out.println(\"You chose south.\");\n"
" System.out.println(deadEnd);\n"
" decisionZero();\n"
" break;\n\n"
" case \"e\":\n"
" System.out.println(\"You chose east.\");\n"
" System.out.println(deadEnd);\n"
" decisionZero();\n"
" break;\n\n"
" case \"w\":\n"
" System.out.println(\"You chose west.\");\n"
" System.out.println(gettingCloser);\n"
" decisionTwo();\n"
" break;\n\n"
" }\n"
" }\n"
" \n"
" public static void decisionTwo()\n"
" {\n"
" System.out.println(\"Decision Point 2\");\n"
" System.out.println(\"Choose a direction Mr. Mouse\");\n"
" String direction = scan.nextLine();\n"
" int rndDecion = (int)(Math.random()*2);\n"
" switch (direction.toLowerCase()) {\n"
" case \"n\":\n"
" System.out.println(\"You chose north.\");\n"
" System.out.println(gettingCloser);\n"
" decisionThree();\n"
" break;\n\n"
" case \"s\":\n"
" System.out.println(\"You chose south.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" }\n"
" break;\n\n"
" case \"e\":\n"
" System.out.println(\"You chose east.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" }\n"
" break;\n\n"
" case \"w\":\n"
" System.out.println(\"You chose west.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" }\n"
" break;\n\n"
" }\n"
" }\n"
" \n"
" public static void decisionThree()\n"
" {\n"
" System.out.println(\"Decision Point 3\");\n"
" System.out.println(\"Choose a direction Mr. Mouse\");\n"
" String direction = scan.nextLine();\n"
" int rndDecion = (int)(Math.random()*3);\n"
" switch (direction.toLowerCase()) {\n"
" case \"n\":\n"
" System.out.println(\"You chose north.\");\n"
" System.out.println(gettingCloser);\n"
" decisionFour();\n"
" break;\n\n"
" case \"s\":\n"
" System.out.println(\"You chose south.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" case 2:\n"
" decisionTwo();\n"
" }\n"
" break;\n\n"
" case \"e\":\n"
" System.out.println(\"You chose east.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" case 2:\n"
" decisionTwo();\n"
" }\n"
" break;\n\n"
" case \"w\":\n"
" System.out.println(\"You chose west.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" case 2:\n"
" decisionTwo();\n"
" }\n"
" break;\n\n"
" }\n"
" }\n"
" \n"
" public static void decisionFour()\n"
" {\n"
" System.out.println(\"Decision Point 4\");\n"
" System.out.println(\"Choose a direction Mr. Mouse\");\n"
" String direction = scan.nextLine();\n"
" int rndDecion = (int)(Math.random()*4);\n"
" switch (direction.toLowerCase()) {\n"
" case \"n\":\n"
" System.out.println(\"You chose north.\");\n"
" System.out.println(gettingCloser);\n"
" decisionFive();\n"
" break;\n\n"
" case \"s\":\n"
" System.out.println(\"You chose south.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" case 2:\n"
" decisionTwo();\n"
" case 3:\n"
" decisionThree();\n"
" }\n"
" break;\n\n"
" case \"e\":\n"
" System.out.println(\"You chose east.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" case 2:\n"
" decisionTwo();\n"
" case 3:\n"
" decisionThree();\n"
" }\n"
" break;\n\n"
" case \"w\":\n"
" System.out.println(\"You chose west.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" case 2:\n"
" decisionTwo();\n"
" case 3:\n"
" decisionThree();\n"
" }\n"
" break;\n\n"
" }\n"
" }\n\n"
" public static void decisionFive()\n"
" {\n"
" System.out.println(\"Decision Point 5\");\n"
" System.out.println(\"Choose a direction Mr. Mouse\");\n"
" String direction = scan.nextLine();\n"
" int rndDecion = (int)(Math.random()*5);\n"
" switch (direction.toLowerCase()) {\n"
" case \"n\":\n"
" System.out.println(\"You chose north.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" case 2:\n"
" decisionTwo();\n"
" case 3:\n"
" decisionThree();\n"
" case 4:\n"
" decisionFour();\n"
" }\n"
" break;\n\n"
" case \"s\":\n"
" System.out.println(\"You chose south.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" case 2:\n"
" decisionTwo();\n"
" case 3:\n"
" decisionThree();\n"
" case 4:\n"
" decisionFour();\n"
" }\n"
" break;\n\n"
" case \"e\":\n"
" System.out.println(\"You chose east.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" case 2:\n"
" decisionTwo();\n"
" case 3:\n"
" decisionThree();\n"
" case 4:\n"
" decisionFour();\n"
" }\n"
" break;\n\n"
" case \"w\":\n"
" System.out.println(\"You chose west.\");\n"
" System.out.println(gettingCloser);\n"
" decisionSix();\n"
" break;\n\n"
" }\n"
" }\n\n"
" public static void decisionSix()\n"
" {\n"
" System.out.println(\"Decision Point 6\");\n"
" System.out.println(\"Choose a direction Mr. Mouse\");\n"
" String direction = scan.nextLine();\n"
" int rndDecion = (int)(Math.random()*5);\n"
" switch (direction.toLowerCase()) {\n"
" case \"n\":\n"
" System.out.println(\"You chose north.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" case 2:\n"
" decisionTwo();\n"
" case 3:\n"
" decisionThree();\n"
" case 4:\n"
" decisionFour();\n"
" }\n"
" break;\n\n"
" case \"s\":\n"
" System.out.println(\"You chose south.\");\n"
" System.out.println(deadEnd);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" case 2:\n"
" decisionTwo();\n"
" case 3:\n"
" decisionThree();\n"
" case 4:\n"
" decisionFour();\n"
" }\n"
" break;\n\n"
" case \"e\":\n"
" System.out.println(\"You chose east.\");\n"
" System.out.println(\"Victory cheese!\");\n"
" break;\n\n"
" case \"w\":\n"
" System.out.println(\"You chose west.\");\n"
" System.out.println(gettingCloser);\n"
" switch (rndDecion) {\n"
" case 0:\n"
" decisionZero();\n"
" case 1:\n"
" decisionOne();\n"
" case 2:\n"
" decisionTwo();\n"
" case 3:\n"
" decisionThree();\n"
" case 4:\n"
" decisionFour();\n"
" }\n"
" break;\n\n"
" }\n"
" }\n\n\n"
" // the main method is COMPLETE. Add/change nothing here.\n"
" public static void main(String[] args) \n"
" {\n"
" decisionZero(); //only line in main method.\n"
" }\n\n\n\n"
"}")
subst = "()\\n {\\n clearScreen();"
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
if result:
print (result)
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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 Python, please visit: https://docs.python.org/3/library/re.html