Leser: 3
|< 1 2 3 4 5 >| | 46 Einträge, 5 Seiten |
QuoteSeveral special variables also refer back to portions of the previous match. $+ returns whatever the last bracket match matched. $& returns the entire matched string. (At one point $0 did also, but now it returns the name of the program.) $` returns everything before the matched string. And $' returns everything after the matched string.
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# use strict;
use Wx qw(wxRED :everything);
# use RegExEdit;
#####################################################
package RegExEdit;
use base 'Wx::App';
$RegExEdit::VERSION = '0.1';
# use Dialog;
use Wx::Event qw(EVT_TEXT);
my $frame="";
sub OnInit {
my( $this ) = shift;
$frame = Dialog->new( );
$this->SetTopWindow( $frame );
$frame->SetTitle("RegExEdit - $RegExEdit::VERSION");
EVT_TEXT($frame,$frame->{text_regex}->GetId,\&OnRegEx);
EVT_TEXT($frame,$frame->{text_match}->GetId,\&OnRegEx);
OnRegEx();
$frame->Show( 1 );
}
sub OnRegEx {
my( $self, $event ) = @_;
#$frame->{text_log}->AppendText("Entering RegEx
");
my $regex = $frame->{text_regex}->GetValue();
my $okay = 1;
eval {m/$regex/;};
$okay =0 if $@;
if ($okay && $frame->{text_match}->GetValue() =~ m/$regex/) {
$frame->{text_log}->AppendText("Matcht
");
if (@+ > 1) {
styleMatch($frame->{text_match}, @+);
}
}
$frame->{text_log}->SetDefaultStyle(Wx::TextAttr->new(Wx::Colour->new('red')));
$frame->{text_log}->AppendText("Error in RegEx: $@") if $@;
}
sub styleMatch {
#print "Entering styler:
";
my $text_ctrl = shift;
my $text = $text_ctrl->GetValue();
my @colours = qw (red blue green yellow);
$text_ctrl->SetValue("");
#print "\tMatch text: $text
";
my @offsets = @_;
my $ln_match = shift @offsets;
my $i = 1;
my $lende = 0;
foreach (@offsets) {
my $length = length(${"$i"});
my $ende = $_;
my $start= $ende-$length;
#print "\tEnde:$ende
";
#print "\tAnfang:$start
";
#print "\tLänge:$length
";
# Text davor
$text_ctrl->AppendText( substr($text,$lende,($start-$lende)));
$text_ctrl->SetDefaultStyle(
Wx::TextAttr->new(
Wx::Colour->new('black'),
Wx::Colour->new($colours[$i])
)
);
$text_ctrl->AppendText(${$i});
$text_ctrl->SetDefaultStyle(
Wx::TextAttr->new(
Wx::Colour->new('black'),
Wx::Colour->new('white')
)
);
#print "\tText davor: ".substr($text,$lende,($start-$lende))."
";
$lende = $ende;
$i++;
# match text
}
#print $_." ".${$i++}."
" foreach @offsets;
}
# ab(cde)fg(hij)
# abcdefghij
##############################################
# generated by wxGlade 0.3.3 on Sun Aug 01 20:02:41 2004
# To get wxPerl visit [URL=http://wxPerl.sourceforge.net/]http://wxPerl.sourceforge.net/[/URL]
use Wx 0.15 qw[:allclasses];
use strict;
package Dialog;
use Wx qw[:everything];
use base qw(Wx::Dialog);
use strict;
# begin wxGlade: ::dependencies
# end wxGlade
sub new {
my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
$parent = undef unless defined $parent;
$id = -1 unless defined $id;
$title = "" unless defined $title;
$pos = wxDefaultPosition unless defined $pos;
$size = wxDefaultSize unless defined $size;
$name = "" unless defined $name;
# begin wxGlade: Dialog::new
$style = wxCAPTION|wxSYSTEM_MENU|wxDIALOG_NO_PARENT
unless defined $style;
$self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name );
$self->{text_regex} = Wx::TextCtrl->new($self, -1, "ab(cde)fg(hij)", wxDefaultPosition, wxDefaultSize, );
$self->{text_match} = Wx::TextCtrl->new($self, -1, "abcdefghij", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_RICH);
$self->{text_log} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
$self->do_layout();
return $self;
# end wxGlade
}
sub set_properties
my $self = shift;
$self->SetTitle("dialog_2");
$self->SetSize(400, 300);
# end wxGlade
}
sub do_layout
my $self = shift;
$self->{sizer_1} = Wx::BoxSizer->new(wxVERTICAL);
$self->{grid_sizer_1} = Wx::FlexGridSizer->new(3, 1, 0, 0);
$self->{grid_sizer_1}->Add($self->{text_regex}, 0, wxEXPAND, 0);
$self->{grid_sizer_1}->Add($self->{text_match}, 0, wxEXPAND, 0);
$self->{grid_sizer_1}->Add($self->{text_log}, 0, wxEXPAND, 0);
$self->{grid_sizer_1}->AddGrowableRow(1);
$self->{grid_sizer_1}->AddGrowableRow(2);
$self->{grid_sizer_1}->AddGrowableCol(0);
$self->{sizer_1}->Add($self->{grid_sizer_1}, 1, wxEXPAND, 0);
$self->SetAutoLayout(1);
$self->SetSizer($self->{sizer_1});
$self->Layout();
# end wxGlade
}
# end of class Dialog
package main;
my $app = RegExEdit->new();
$app->MainLoop;
QuoteForbidden
You don't have permission to access /pub/User/ManuelRenz/ on this server.
|< 1 2 3 4 5 >| | 46 Einträge, 5 Seiten |