fork(2) download
  1. import re
  2.  
  3. test_str = """
  4. /*--------------------------------*- C++ -*----------------------------------*\
  5. | ========= | |
  6. | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
  7. | \\ / O peration | Version: 5 |
  8. | \\ / A nd | Web: www.OpenFOAM.org |
  9. | \\/ M anipulation | |
  10. \*---------------------------------------------------------------------------*/
  11. FoamFile
  12. {
  13. version 2.0;
  14. format ascii;
  15. class dictionary;
  16. object blockMeshDict;
  17. }
  18. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  19.  
  20. convertToMeters 0.001;
  21.  
  22. vertices
  23. (
  24. (-20.6 0 -0.5)
  25. (-20.6 25.4 -0.5) /* Some comment */
  26. (0 -25.4 -0.5)
  27. (0 0 -0.5)
  28. (0 25.4 -0.5)
  29. (206 -25.4 -0.5)
  30. (206 0 -0.5)
  31. (206 25.4 -0.5)
  32. (290 -16.6 -0.5)
  33. (290 0 -0.5)
  34. (290 16.6 -0.5)
  35.  
  36. (-20.6 0 0.5)
  37. (-20.6 25.4 0.5)
  38. (0 -25.4 0.5)
  39. (0 0 0.5)
  40. (0 25.4 0.5)
  41. (206 -25.4 0.5)
  42. (206 0 0.5)
  43. (206 25.4 0.5)
  44. (290 -16.6 0.5)
  45. (290 0 0.5)
  46. (290 16.6 0.5)
  47. /*(1 2 3 4)*/ // Commented tuple
  48. //(1 2 3 4)
  49. );
  50.  
  51. /* vertices commented
  52. vertices
  53. (
  54. (-20.6 0 -0.5)
  55. (-20.6 25.4 -0.5)
  56. (0 -25.4 -0.5)
  57. (0 0 -0.5)
  58. (0 25.4 -0.5)
  59. (206 -25.4 -0.5)
  60. (206 0 -0.5)
  61. (206 25.4 -0.5)
  62. (290 -16.6 -0.5)
  63. (290 0 -0.5)
  64. (290 16.6 -0.5)
  65. )
  66. */
  67.  
  68. negY
  69. (
  70. (2 4 1)
  71. (1 3 0.3)
  72. );
  73.  
  74. posY
  75. (
  76. (1 4 2)
  77. (2 3 4)
  78. (2 4 0.25)
  79. );
  80.  
  81. posYR
  82. (
  83. (2 1 1)
  84. (1 1 0.25)
  85. );
  86.  
  87.  
  88. blocks
  89. (
  90. hex (0 3 4 1 11 14 15 12)
  91. (18 30 1)
  92. simpleGrading (0.5 $posY 1)
  93.  
  94. hex (2 5 6 3 13 16 17 14)
  95. (180 27 1)
  96. edgeGrading (4 4 4 4 $negY 1 1 $negY 1 1 1 1)
  97.  
  98. hex (3 6 7 4 14 17 18 15)
  99. (180 30 1)
  100. edgeGrading (4 4 4 4 $posY $posYR $posYR $posY 1 1 1 1)
  101.  
  102. hex (5 8 9 6 16 19 20 17)
  103. (25 27 1)
  104. simpleGrading (2.5 1 1)
  105.  
  106. hex (6 9 10 7 17 20 21 18)
  107. (25 30 1)
  108. simpleGrading (2.5 $posYR 1)
  109. );
  110.  
  111. edges
  112. (
  113. );
  114.  
  115. boundary
  116. (
  117. inlet
  118. {
  119. type patch;
  120. faces
  121. (
  122. (0 1 12 11)
  123. );
  124. }
  125. outlet
  126. {
  127. type patch;
  128. faces
  129. (
  130. (8 9 20 19)
  131. (9 10 21 20)
  132. );
  133. }
  134. upperWall
  135. {
  136. type wall;
  137. faces
  138. (
  139. (1 4 15 12)
  140. (4 7 18 15)
  141. (7 10 21 18)
  142. );
  143. }
  144. lowerWall
  145. {
  146. type wall;
  147. faces
  148. (
  149. (0 3 14 11)
  150. (3 2 13 14)
  151. (2 5 16 13)
  152. (5 8 19 16)
  153. );
  154. }
  155. frontAndBack
  156. {
  157. type empty;
  158. faces
  159. (
  160. (0 3 4 1)
  161. (2 5 6 3)
  162. (3 6 7 4)
  163. (5 8 9 6)
  164. (6 9 10 7)
  165. (11 14 15 12)
  166. (13 16 17 14)
  167. (14 17 18 15)
  168. (16 19 20 17)
  169. (17 20 21 18)
  170. );
  171. }
  172. );
  173. // ************************************************************************* //
  174. """
  175.  
  176. # Clean comments:
  177. test_str = re.sub(r"//.*", '', test_str)
  178. test_str = re.sub(r"/\*.*?\*/", '', test_str, 0, re.DOTALL)
  179.  
  180. # Match main group
  181. matches = re.findall(r"\bvertices\s*\((\s*(?:\([^)]+\)\s*)+)\)", test_str, re.MULTILINE | re.DOTALL)
  182.  
  183. # Fetch tuples
  184. matches2 = re.findall(r"\([^)]+\)", matches[0], re.MULTILINE | re.DOTALL)
  185. print matches2
  186.  
Success #stdin #stdout 0.04s 65452KB
stdin
Standard input is empty
stdout
['(-20.6 0 -0.5)', '(-20.6 25.4 -0.5)', '(0 -25.4 -0.5)', '(0 0 -0.5)', '(0 25.4 -0.5)', '(206 -25.4 -0.5)', '(206 0 -0.5)', '(206 25.4 -0.5)', '(290 -16.6 -0.5)', '(290 0 -0.5)', '(290 16.6 -0.5)', '(-20.6 0 0.5)', '(-20.6 25.4 0.5)', '(0 -25.4 0.5)', '(0 0 0.5)', '(0 25.4 0.5)', '(206 -25.4 0.5)', '(206 0 0.5)', '(206 25.4 0.5)', '(290 -16.6 0.5)', '(290 0 0.5)', '(290 16.6 0.5)']