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

Einen String ausschliessen RegEx

Leser: 3


<< >> 3 Einträge, 1 Seite
Gast Gast
 2009-01-29 18:25
#118517 #118517
Hi Community,

ich sitze vor einem kleinen Problemchen. Ich möchte alle HTML-Tags löschen, außer die, wo der String 'fc', gefolgt von Zahlen, vorkommt.

Code: (dl )
s/<[^>fc\d+]*>//gi;


Das bringts leider nicht. Hat jmd. eine Idee?

Gruß
pq
 2009-01-29 18:49
#118518 #118518
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
das hat nichts mit CGI zu tun.
auch wenn du das in einem cgiskript laufen lassen willst, hat das problem an sich nichts damit zu tun. du willst strings bearbeiten. klassische aufgabe von perl. gehört zu "allgemeines".
ich verschieb mal.
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
renee
 2009-01-30 09:29
#118522 #118522
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Du schließt hier eine Zeichenklasse aus. Dein RegEx sagt das hier:

Erst ein "<", dann weder ein ">" noch ein "f" noch ein "c"...

Probier mal (ungetestet):
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
#!/usr/bin/perl

use strict;
use warnings;

my $content = qq~<html><body>Hallo<fc>Test</body></html>~;
$content =~ s/<(?!fc).*?>//g;

print $content


Lesestoff:
perldoc perlre
perldoc perlretut
perldoc perlreref
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/
<< >> 3 Einträge, 1 Seite



View all threads created 2009-01-29 18:25.