php – Regular Expression Schnipsel – Escaping “/”

closeThis post was published more than three months ago. Please note that the information offered here may no longer be current and valid. Therefore, please inform yourself about this topic elsewhere. If there is any new information, you can also send me a comment. Thank you so much!

Hier ein kleines Beispiel wie man die Lesbarkeit von RegEx durch den Delimiter  “#” verbessern kann … ;)

$zeichenkette = "suckup.de Informationen / test, lall / Linux / lall123";
#$suchmuster = "/^[^\/]*\/[^\/]*\/[^\/]*\/[^\/]/";
$suchmuster = "#^[^/]*/[^/]*/[^/]*/[^/]#";
preg_match($suchmuster, $zeichenkette, $treffer);
print_r($treffer);

 

Ausgabe:

Array ( [0] => suckup.de Informationen / test, lall / Linux / )

Published by

voku

Lars Moelleken | Ich bin root, ich darf das!