m{ (record .*? function \s* \w+\(\) .*? end;) }xmsg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#!/usr/bin/perl use strict; use warnings; my $s = <<ENDSTRING; TFoo = record ... no functions here ... end; TFoo = record ... event01 here function Bar(): Integer; ... end; TFoo = record ... no functions here eventually event02 here no functions here ... end; TFoo = record ... function Bas(): Integer; event03 here ... end; TFoo = record ... no functions here ... end; TFoo = record ... event04 here function Bat(): Integer; event05 here ... end; TFoo = record ... no functions here ... end; TFoo = record ... function Bau(): Integer; ... end; TFoo = record ... no functions here ... end; ENDSTRING print for $s =~ m{ (record (?:[^e]|\we|\be(?!nd;))+? function \s+ \w+\(\) .+? end; \s*) }xmsg;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
use strict; use warnings; my $s = <<ENDSTRING; TFoo = record ... no functions here ... end; TFoo = record ... function Bar(): Integer; ... end; TFoo = record ... no functions here append; ... end; TFoo = record ... function Bar(): Integer; append; function Foo(): Integer; ... end; TFoo = record ... no functions here ... end; ENDSTRING print "$_\n" for $s =~ m/(\brecord\b([^e]*?|\Be|\be(?!nd\s*;))*?\bfunction\s+\w+\(\).*?\bend\s*;)/msg;
2014-12-17T13:17:43 clmsDie Idee mit [^e]|e(?!nd) ist sehr gut. Man kann das Oder noch erweitern, indem man auf [^e]|\Be|\be(?!nd) testet