$re = '/^(lib32-[a-zA-Z0-9\.\-]*?)\-[0-9\.]*\-[0-9\.]$/m';
$str = 'lib32-bluez-libs-5.41-1
lib32-dbus-glib-0.106-1
lib32-gconf-3.2.6-1
lib32-jansson-2.7-2
lib32-kmod-22-1
lib32-libdaemon-0.14-4
lib32-libical-2.0.0-3
lib32-libmbim-1.12.4-1
lib32-libmm-glib-1.4.14-2
lib32-libndp-1.6-1
lib32-libnm-glib-1.2.2-1
lib32-libqmi-1.12.10-1
lib32-libteam-1.23-1
lib32-libudev0-182-2';
$subst = "";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php