Thread Regex: Suchen innerhalb eines Matches? (8 answers)
Opened by Muffi at 2014-12-17 10:38

clms
 2014-12-17 14:17
#178785 #178785
User since
2010-08-29
373 Artikel
BenutzerIn
[default_avatar]
Die Idee mit [^e]|e(?!nd) ist sehr gut. Man kann das Oder noch erweitern, indem man auf [^e]|\Be|\be(?!nd) testet:

Code (perl): (dl )
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;

Last edited: 2014-12-17 14:18:48 +0100 (CET)

View full thread Regex: Suchen innerhalb eines Matches?