Thread regex max ein "-" (12 answers)
Opened by Gast at 2007-07-01 15:37

pq
 2007-07-01 17:43
#78112 #78112
User since
2003-08-04
12209 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

View full thread regex max ein "-"