$re = '/^\w+\s+\d+\s+\d{2}(?::\d{2}){2}\s+(?P<devicename1>\S+)/m';
$str = 'Nov 1 00:00:21 akdcs20.ftc.abcd-ipsn AKDCS20 fpc0 LBCM-L2,brcm_port_learning_config(),1258:(brcm_port_learning_config:1258) Setting L2 learning unit:0,port_num:44, learn_flg 5
Nov 1 01:27:16 spnztpm01.abcd-ipsn 553177: LC/0/0/CPU0:Nov 1 01:27:16.040 : ifmgr[200]: %PKT_INFRA-LINEPROTO-5-UPDOWN : Line protocol on Interface TenGigE0/0/0/1.172153, changed state to Up
Oct 31 23:59:56 akdcs19.ftc.abcd-ipsn AKDCS19 ufdd[1679]: ufd_group_config_if_lookup ifname ae4 ';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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