3v4l.org

run code in 300+ PHP versions simultaneously
<?php //(?=) - positive lookahead $string = "achei quebra; tem aqui;"; $regex = "/\w+(?=;)/"; preg_match_all($regex, $string, $matches); var_dump($matches); //(?!) - negative lookahead / $regex = "/\b\w+\b(?!;)/"; preg_match_all($regex, $string, $matches); var_dump($matches); //(?<=) - positive lookbehind $string = "dra Julia \ndr Marcos \ndr Mateus \ndra Ana"; $regex = "/(?<=dra\s)(\w+)/im"; preg_match_all($regex, $string, $matches); var_dump($matches); //(?<!) - negative lookbehind $regex = "/(?<!^dra\s)\b\w+\b$/im"; preg_match_all($regex, $string, $matches); var_dump($matches); /* (?>) - atomic group */

preferences:
69.54 ms | 402 KiB | 5 Q