Schrift
Wiki:Tipp zum Debugging: use Data::Dumper; local $Data::Dumper::Useqq = 1; print Dumper \@var;
[thread]9145[/thread]

regex max ein "-" (Seite 2)



<< |< 1 2 >| >> 13 Einträge, 2 Seiten
pq
 2007-07-01 17:43
#78112 #78112
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
aehmmm... wieso nicht einfach tr///?
Code: (dl )
1
2
3
4
5
6
7
8
9
10
@strings = qw(abc-def abc--def abc-d-ef abcdef ---abc--def--);
for my $string (@strings) {
 print "<$string> " . ($string =~ tr/-// == 1 ? "ok" : "not ok");
}
=>
<abc-def> ok
<abc--def> not ok
<abc-d-ef> not ok
<abcdef> not ok
<---abc--def--> not ok
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
RPerl
 2007-07-01 18:05
#78113 #78113
User since
2006-11-26
384 Artikel
BenutzerIn

user image
Geht das nur mir so, oder versteht jemand den code von pq auch nicht? *g*

// Edit: Ok, nun verstehe ich. Nice geloest....\n\n

<!--EDIT|RPerl|1183298934-->
havi
 2007-07-02 14:39
#78114 #78114
User since
2003-08-04
2036 Artikel
BenutzerIn
[Homepage]
user image
[quote=Guest,01.07.2007, 13:37]hi,
ich möchte eine if schleife ausführen wenn max 1 und min 1 "-" in einen string vorkommt... ich komm aber nicht auf den regex...

pls help[/quote]
if-Abfrage - denn if-Schleife gibts net...
<< |< 1 2 >| >> 13 Einträge, 2 Seiten



View all threads created 2007-07-01 15:37.