# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^\d+."
test_str = ("1. // #include <conio.h>\n"
"2. // #include <stdio.h>\n"
"3. #include <iostream>\n"
"4. // #include <ctype.h>\n"
"5. #include <cstring>\n"
"6. using namespace std;\n"
"7. class CON_VAT\n"
"8. {\n"
"9. protected:\n"
"10. char *ten;\n"
"11. public:\n"
"12. CON_VAT()\n"
"13. {ten = NULL;\n"
"14. }\n"
"15. CON_VAT(char *ten1)\n"
"16. {\n"
"17. strcpy(ten,ten1);\n"
"18. }\n"
"19. virtual void xung_ten()\n"
"20. { }\n"
"21. } ;\n"
"22. class CON_MEO:public CON_VAT\n"
"23. {\n"
"24. public:\n"
"25. CON_MEO() : CON_VAT()\n"
"26. { }\n"
"27. CON_MEO(char *ten1) : CON_VAT(ten1)\n"
"28. { }\n"
"29. virtual void xung_ten()\n"
"30. {\n"
"31. cout << \"\\nToi la chu meo: \" << ten ;\n"
"32. }\n"
"33. };\n"
"34. class CON_CHO:public CON_VAT\n"
"35. {\n"
"36. public:\n"
"37. CON_CHO() : CON_VAT()\n"
"38. { }\n"
"39. CON_CHO(char *ten1) : CON_VAT(ten1)\n"
"40. { }\n"
"41. virtual void xung_ten()\n"
"42. {\n"
"43. cout << \"\\nToi la chu cho: \" << ten ;\n"
"44. }\n"
"45. };\n"
"46. class DS_CON_VAT // Danh sach con vat\n"
"47. {\n"
"48. private:\n"
"49. int max_so_con_vat;\n"
"50. int so_con_vat;\n"
"51. CON_VAT **h ;\n"
"52. public:\n"
"53. DS_CON_VAT(int max);\n"
"54. ~DS_CON_VAT();\n"
"55. int nhap(CON_VAT *c);\n"
"56. CON_VAT* xuat(int n);\n"
"57. void thong_ke();\n"
"58. } ;\n"
"59. DS_CON_VAT::DS_CON_VAT(int max)\n"
"60. {\n"
"61. max_so_con_vat = max;\n"
"62. so_con_vat = 0;\n"
"63. h = new CON_VAT*[max];\n"
"64. for (int i=0; i<max; ++i)\n"
"65. h[i] = NULL;\n"
"66. }\n"
"67. DS_CON_VAT::~DS_CON_VAT()\n"
"68. {\n"
"69. max_so_con_vat = 0;\n"
"70. so_con_vat = 0;\n"
"71. delete h;\n"
"72. }\n"
"73. int DS_CON_VAT::nhap(CON_VAT *c)\n"
"74. {\n"
"75. if (so_con_vat==max_so_con_vat)\n"
"76. return 0;\n"
"77. int i=0;\n"
"78. while (h[i]!=NULL) ++i;\n"
"79. h[i]=c;\n"
"80. so_con_vat++ ;\n"
"81. return (i+1);\n"
"82. }\n"
"83. CON_VAT* DS_CON_VAT::xuat(int n)\n"
"84. {\n\n"
"85. if (n<1 || n > max_so_con_vat)\n"
"86. return NULL ;\n"
"87. --n ;\n"
"88. if (h[n])\n"
"89. {\n"
"90. CON_VAT *c = h[n];\n"
"91. h[n]=NULL;/*----------------------???---------------------*/\n"
"92. so_con_vat-- ;\n"
"93. return c;\n"
"94. }\n"
"95. else\n"
"96. return NULL;\n"
"97. }\n"
"98. void DS_CON_VAT::thong_ke()\n"
"99. {\n"
"100. if (so_con_vat)\n"
"101. {\n"
"102. cout << \"\\n\" ;\n"
"103. for (int i=0; i<max_so_con_vat; ++i)\n"
"104. if (h[i])\n"
"105. h[i]->xung_ten();\n"
"106. }\n"
"107. }\n"
"108. CON_CHO c1(\"MUC\");\n"
"109. CON_CHO c2(\"VEN\");\n"
"110. CON_CHO c3(\"LAI\");\n"
"111. CON_CHO c4(\"NHAT\");\n"
"112. CON_CHO c5(\"BONG\");\n"
"113. CON_MEO m1(\"MUOP\");\n"
"114. CON_MEO m2(\"DEN\");\n"
"115. CON_MEO m3(\"TRANG\");\n"
"116. CON_MEO m4(\"TAM THE\");\n"
"117. CON_MEO m5(\"VANG\");\n"
"118. DS_CON_VAT d(20);\n"
"119. int main()\n"
"120. {\n\n"
"121. //clrscr();\n"
"122. d.nhap(&c1);\n"
"123. int im2 = d.nhap(&m2);\n"
"124. d.nhap(&c3);\n"
"125. d.nhap(&m1);\n"
"126. int ic4 = d.nhap(&c4);\n"
"127. d.nhap(&c5);\n"
"128. d.nhap(&m5);\n"
"129. d.nhap(&c2);\n"
"130. d.nhap(&m3);\n"
"131. d.thong_ke();\n"
"132. d.xuat(im2);\n"
"133. d.xuat(ic4);\n"
"134. d.thong_ke();\n"
"135. //getch();\n"
"136. }")
subst = ""
# 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