$re = '/(?ms)(^NAME.*?)^\s+^\d/ms';
$str = 'SQL*Plus: Release 11.2.0.1.0 Production on Wed Jan 27 13:46:07 2016
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
NAME
--------------------------------------------------------------------------------
Agent-Job Follow Up Missed Group D
Agent-Job Follow Up Missed Group E
Audit Archive
Day BGO - 705 and 705NA - A (2)
Day BGO - ERR Quebec - A
Dispatch Lunch Break Agent (Pre-Agent) - Group D
Helper Job Agent (Amend, Prevent, Lead) Group A
Incomplete Tasks Display Status Cleanup - Group A
Jeopardy Agent (Late EnRoute, OnSite, Complete) Group A
Jeopardy Agent (Late EnRoute, OnSite, Complete) Group B
Lunch Break Report Agent(Post-Agent) - Group A
NAME
--------------------------------------------------------------------------------
MST Validation - Group A
MST Validation - Group C
Unschedule INHS Tasks
Unschedule Jobs with Schedule Update Failure - Group E
15 rows selected.
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options';
preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 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