Advertisement
default_ex

Regex for C-like function body matching

Mar 31st, 2012
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. \{\s*(?<Body>
  2. (?>
  3. # inside a multi line comment
  4. (?(InCommentML)
  5. (?<Comments>(?:[^*/]|(?!\*)/|\*(?<!/))+)
  6. \*/\s* (?<-InCommentML>)
  7.  
  8. # not inside a multi line comment
  9. |
  10. (?:
  11. # inside a single line comment
  12. (?(InCommentSL)
  13. (?<Comments>[^\n\r]+)
  14. [\r\n]+ (?<-InCommentSL>)
  15.  
  16. # not in a comment
  17. |
  18. (?:
  19. # single line comment
  20. // (?<InCommentSL>)
  21. |
  22. # multi line comment
  23. /\* (?<InCommentML>)
  24. |
  25. # match lines until any of the following are found: //, /*, new line, or change scope
  26. (?<Code>(?!/)/|/(?!\*)|(?!/)\*|[^{}\r\n/*]+)\s*
  27. |
  28. # open scope
  29. \{\s* (?<Scope>)
  30. |
  31. # close scope
  32. \}\s* (?<-Scope>)
  33. )
  34. )
  35. )
  36. )
  37. )*
  38.  
  39. # fail clause: a scope was not closed
  40. (?(Scope)(?!))
  41.  
  42. )\}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement