t465.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import re
  2. print "\nSyntax: ."
  3. print re.findall(".","")
  4. print re.findall(".","a")
  5. print re.findall(".a","a")
  6. print re.findall("a","a")
  7. print re.findall("a.","a\n")
  8. print re.findall(".a","ba")
  9. print "\nSyntax: ^"
  10. print re.findall("^","")
  11. print re.findall("a^","")
  12. print re.findall("^a","ba")
  13. print re.findall("^a","ab")
  14. print re.findall("^a","\na")
  15. print re.findall("a^","a")
  16. print "\nSyntax: $"
  17. print re.findall("$","")
  18. print re.findall("$a","a")
  19. print re.findall("a$","a")
  20. print re.findall("a$","ab")
  21. print re.findall("a$","a\nb")
  22. print re.findall("a$","a\n")
  23. print "\nSyntax: *"
  24. print re.findall("a*","")
  25. print re.findall("ab*","a")
  26. print re.findall("ab*","ab")
  27. print re.findall("ab*","abbbbb")
  28. print re.findall("ab*","ba")
  29. print re.findall("ab*","bbbb")
  30. print "\nSyntax: +"
  31. print re.findall("a+","")
  32. print re.findall("ab+","a")
  33. print re.findall("ab+","ab")
  34. print re.findall("ab+","abbbbb")
  35. print re.findall("ab+","ba")
  36. print re.findall("ab+","bbbb")
  37. print "\nSyntax: ?"
  38. print re.findall("a?","")
  39. print re.findall("ab?","a")
  40. print re.findall("ab?","ab")
  41. print re.findall("ab?","abbbbb")
  42. print re.findall("ab?","ba")
  43. print re.findall("ab?","bbbb")
  44. print "\nSyntax: *?"
  45. print re.findall("a*?","a")
  46. print re.findall("ab*?","abbbb")
  47. print re.findall("ab*?","a")
  48. print re.findall("ab*?","")
  49. print "\nSyntax: +?"
  50. print re.findall("a+?","a")
  51. print re.findall("ab+?","abbbb")
  52. print re.findall("ab+?","a")
  53. print re.findall("ab+?","")
  54. print "\nSyntax: ??"
  55. print re.findall("a??","a")
  56. print re.findall("ab??","abbbb")
  57. print re.findall("ab??","a")
  58. print re.findall("ab??","")
  59. print "\nSyntax: {m}"
  60. print re.findall("a{2}","a")
  61. print re.findall("a{2}","aa")
  62. print re.findall("a{2}","aaa")
  63. print "\nSyntax: {m,n}"
  64. print re.findall("a{1,2}b","b")
  65. print re.findall("a{1,2}b","ab")
  66. print re.findall("a{1,2}b","aab")
  67. print re.findall("a{1,2}b","aaab")
  68. print re.findall("a{,2}b","b")
  69. print re.findall("a{,2}b","ab")
  70. print re.findall("a{,2}b","aab")
  71. print re.findall("a{,2}b","aaab")
  72. print re.findall("a{2,}b","b")
  73. print re.findall("a{2,}b","ab")
  74. print re.findall("a{2,}b","aab")
  75. print re.findall("a{2,}b","aaab")
  76. print re.findall("a{3,5}","aaaaaaaaaa")
  77. print re.findall("a{,5}","aaaaaaaaaa")
  78. print re.findall("a{3,}","aaaaaaaaaa")
  79. print "\nSyntax: {m,n}?"
  80. print re.findall("a{1,2}?b","b")
  81. print re.findall("a{1,2}?b","ab")
  82. print re.findall("a{1,2}?b","aab")
  83. print re.findall("a{1,2}?b","aaab")
  84. print re.findall("a{,2}?b","b")
  85. print re.findall("a{,2}?b","ab")
  86. print re.findall("a{,2}?b","aab")
  87. print re.findall("a{,2}?b","aaab")
  88. print re.findall("a{2,}?b","b")
  89. print re.findall("a{2,}?b","ab")
  90. print re.findall("a{2,}?b","aab")
  91. print re.findall("a{2,}?b","aaab")
  92. print re.findall("a{3,5}?","aaaaaaaaaa")
  93. print re.findall("a{,5}?","aaaaaaaaaa")
  94. print re.findall("a{3,}?","aaaaaaaaaa")
  95. print "\nSyntax: []"
  96. print re.findall("[a,b,c]","abc")
  97. print re.findall("[a-z]","bc")
  98. print re.findall("[A-Z,0-9]","abcdefg")
  99. print re.findall("[^A-Z]","ABCDEFGaHIJKL")
  100. print re.findall("[a*bc]","*")
  101. print "\nSyntax: |"
  102. print re.findall("|","")
  103. print re.findall("|a","")
  104. print re.findall("a|b","ba")
  105. print re.findall("h|ello","hello")
  106. print "\nSyntax: (...)"
  107. print re.findall("(b*)","bbbba")
  108. print "\nSyntax: (?...)"
  109. print re.findall("(?:b*)","bbbba")
  110. print re.findall("a(?=b)","a")
  111. print re.findall("a(?=b)","ab")
  112. print re.findall("a(?!b)","a")
  113. print re.findall("a(?!b)","ab")