fork(2) download
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my $content = qq{
  7. module whatever
  8. //endmodule
  9. // endmodule
  10. // asadsadadsa endmodule
  11. // enasaa endmodule asas
  12. /* endmodule */
  13. /* blabl
  14. endmodule // whatever
  15. blabla */
  16. // endmodule // whatever
  17. endmodule // whatever
  18. module nonsense
  19. //
  20. // bla bla
  21. //
  22. endmodule // nonsense
  23. };
  24.  
  25. if ($content =~ m~
  26. module\s+whatever # marks the start of the module
  27. (?: # each instance of this alternation matches one kind of
  28. # module "token"
  29. //.*+ # match a single-line comment
  30. | # or
  31. /[*] # open a block comment
  32. (?:(?![*]/)[\s\S])*+ # match anything as long as it doesn't close the comment
  33. [*]/ # close the block comment
  34. | # or
  35. (?!endmodule)[\s\S] # match anything as long as it doesn't close the module
  36. )*+ # repeat
  37. endmodule
  38. ~x) {
  39. print $&;
  40. }
  41. else
  42. {
  43. print "NOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!!!!!!!!!!\n";
  44. }
Success #stdin #stdout 0s 3740KB
stdin
Standard input is empty
stdout
module whatever
//endmodule
// endmodule
// asadsadadsa endmodule
// enasaa endmodule asas
/* endmodule */
/* blabl
endmodule // whatever
blabla */
// endmodule // whatever
endmodule