Thread Bedingung in Regexp (4 answers)
Opened by roooot at 2009-04-25 15:11

FIFO
 2009-04-25 16:59
#120883 #120883
User since
2005-06-01
469 Artikel
BenutzerIn

user image
Versuch mal:
Code (perl): (dl )
 $meinevariable =~ /http:\/\/www\.foo\.de($|\/.*)/i

Das sollte alles matchen, was hinter 'http://www.foo.de' nix oder '/irgendwas' enthält.
In Deinem Pattern ist nicht so ganz klar,was Du eigentlich zurückbekommen willst, Du hast immer 'foo.de' in $1, (wobei der Punkt im foo.de auch escaped werden sollte) und in $2 denn Kram hinter 'foo.de'.
Edit:
Wenn im Teil hinter 'foo.de'nur genau ein '/' auftauchen darf, also z.B. nicht 'foo.de/bla/blub', musst Du Slahes ausschließen:
Code (perl): (dl )
$meinevariable =~ /http:\/\/www\.foo\.de($|\/[^\/]*)/i

Schönes Mikado-Pattern ;-)
Gruß FIFO
Last edited: 2009-04-25 17:08:31 +0200 (CEST)
Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? -- Brian Kernighan: "The Elements of Programming Style"

View full thread Bedingung in Regexp