Schrift
[thread]996[/thread]

was bedeutet dieser RegEx



<< >> 7 Einträge, 1 Seite
Peddn
 2005-03-31 11:46
#10179 #10179
User since
2003-12-21
33 Artikel
BenutzerIn
[Homepage] [default_avatar]
Hi Leute,

könnt ihr mir mal auf die Sprünge helfen, was bedeutet dieser reguläre Ausdruck?

Code: (dl )
$regexp = "/\bBug {0,1}(\d+)\:/i";


Was löst z.B. einen Match aus?
Gibt es unterschiede zwischen Perl und PHP?

Gruß,
Peddn\n\n

<!--EDIT|Peddn|1112259289-->
renee
 2005-03-31 12:08
#10180 #10180
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Code: (dl )
1
2
3
4
5
6
/\b # prüft auf eine Wortgrenze
Bug # das Wort Bug
{0,1} # 0 oder 1 Leerzeichen
(\d+) # eine oder mehrere Zahlen (in $1 gespeichert)
\: # ein Doppelpunkt
/ix # i -> Case insensitive


Beispiel wäre:
Code: (dl )
Bug 23:
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
pq
 2005-03-31 12:16
#10181 #10181
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
also (bezüglich perl), das sagt CPAN:YAPE::Regex::Explain:
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
(?i-msx:\bBug {0,1}(\d+):)

matches as follows:
 
NODE                     EXPLANATION
----------------------------------------------------------------------
(?i-msx:                 group, but do not capture (case-insensitive)
                        (with ^ and $ matching normally) (with . not
                        matching \n) (matching whitespace and #
                        normally):
----------------------------------------------------------------------
 \b                       the boundary between a word char (\w) and
                          something that is not a word char
----------------------------------------------------------------------
 Bug                      'Bug'
----------------------------------------------------------------------
  {0,1}                   ' ' (between 0 and 1 times (matching the
                          most amount possible))
----------------------------------------------------------------------
 (                        group and capture to \1:
----------------------------------------------------------------------
   \d+                      digits (0-9) (1 or more times (matching
                            the most amount possible))
----------------------------------------------------------------------
 )                        end of \1
----------------------------------------------------------------------
 :                        ':'
----------------------------------------------------------------------
)                        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
Peddn
 2005-03-31 12:52
#10182 #10182
User since
2003-12-21
33 Artikel
BenutzerIn
[Homepage] [default_avatar]
VIelen Dank, das hat mir schon weitergeholfen...
Und CPAN: YAPE::Regex::Explain: werde ich mir mal genauer anschauen :)

Gruß,
Peddn
Taulmarill
 2005-03-31 12:53
#10183 #10183
User since
2004-02-19
1750 Artikel
BenutzerIn

user image
wobei man noch anmerken könnte, dass {0,1} nur eine aufwendigere schreibweise für ? ist. evtl. ist ? sogar schneller.
$_=unpack"B*",~pack"H*",$_ and y&1|0& |#&&print"$_\n"for@.=qw BFA2F7C39139F45F78
0A28104594444504400 0A2F107D54447DE7800 0A2110453444450500 73CF1045138445F4800 0
F3EF2044E3D17DE 8A08A0451412411 F3CF207DF41C79E 820A20451412414 83E93C4513D17D2B
[E|B]
 2005-03-31 14:56
#10184 #10184
User since
2003-08-08
2561 Artikel
HausmeisterIn
[Homepage] [default_avatar]
[quote=renee,31.03.2005, 10:08]
Code: (dl )
(\d+) # eine oder mehrere Zahlen (in $1 gespeichert)
[/quote]
Bei PHP gibt es $1 AFAIK nicht. Die regulären Ausdrücke von PHP sind zwar größtenteils an Perl 5.005 angelehnt und entsprechen POSIX Standart, ob es aber $1 gibt wage ich zu bezweifeln.
Gruß, Erik!

s))91\&\/\^z->sub{}\(\@new\)=>69\&\/\^z->sub{}\(\@new\)=>124\&\/\^z->sub{}\(\@new\)=>);
$_.=qq~66\&\/\^z->sub{}\(\@new\)=>93~;for(@_=split(/\&\/\^z->sub{}\(\@new\)=>/)){print chr;}

It's not a bug, it's a feature! - [CGI-World.de]
renee
 2005-03-31 15:24
#10185 #10185
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
stimmt, in PHP heißt das \1 (gibt es ja auch in Perl)... Hab zu spät gesehen, dass es sich um PHP handelt, aber das Prinzip dürfte rübergekommen sein...
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
<< >> 7 Einträge, 1 Seite



View all threads created 2005-03-31 11:46.