Thread Hilfe bei Regulären Ausdrücken (Regex) (6 answers)
Opened by Student82 at 2010-09-04 18:10

pq
 2010-09-04 20:37
#141171 #141171
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
es gibt da ein nettes perl-modul, mit dem man sich regexes erklären lassen kann. das sieht dann so aus:

Code: (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
36
37
38
39
40
41
42
43
44
45
46
47
perl -wle'use YAPE::Regex::Explain;
my $re = qr/\W*(\w+\W+){1,2}\w+\W*/;
print YAPE::Regex::Explain->new($re)->explain;'
The regular expression:

(?-imsx:\W*(\w+\W+){1,2}\w+\W*)

matches as follows:

NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
\W* non-word characters (all but a-z, A-Z, 0-
9, _) (0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
( group and capture to \1 (between 1 and 2
times (matching the most amount
possible)):
----------------------------------------------------------------------
\w+ word characters (a-z, A-Z, 0-9, _) (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
\W+ non-word characters (all but a-z, A-Z,
0-9, _) (1 or more times (matching the
most amount possible))
----------------------------------------------------------------------
){1,2} end of \1 (NOTE: because you are using a
quantifier on this capture, only the LAST
repetition of the captured pattern will be
stored in \1)
----------------------------------------------------------------------
\w+ word characters (a-z, A-Z, 0-9, _) (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
\W* non-word characters (all but a-z, A-Z, 0-
9, _) (0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread Hilfe bei Regulären Ausdrücken (Regex)