你可以用
/^([a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4})\r?\n(.*(?:\r?\n(?![a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4}).*)*)/igm
见 正则表达式演示 。
该模式包括您的模式以及与该模式或文本结尾匹配的附加部分。
^
([a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4})
\r?\n
(.*(?:\r?\n(?![a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4}).*)*)
.*
(?:\r?\n(?![a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4}).*)*
\r?\n(?![a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4})
JS演示:
var rx = /^([a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4})\r?\n(.*(?:\r?\n(?![a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4}).*)*)/gmi; var str = "Fri Jan 24 05:28:57 2014\r\nMEMORY_TARGET defaulting to 1128267776.\r\n* instance_number obtained from CSS = 1, checking for the existence of node 0... \r\n* node 0 does not exist. instance_number = 1 \r\nStarting ORACLE instance (normal)\r\nLICENSE_MAX_SESSION = 0\r\nLICENSE_SESSIONS_WARNING = 0\r\nInitial number of CPU is 48\r\nNumber of processor cores in the system is 24\r\nNumber of processor sockets in the system is 12\r\nPrivate Interface 'nxge20:1' configured from GPnP for use as a private interconnect.\r\nabc\r\n [name='nxge20:1', type=1, ip=169.254.121.29, mac=00-21-28-0e-8c-ae-00-00-00-00-00-00-00-00-00-00-00-2f-ff-ff, net=169.254.0.0/16, mask=255.255.0.0, use=haip:cluster_interconnect/62]\r\nPublic Interface 'nxge0' configured from GPnP for use as a public interface.\r\n [name='nxge0', type=1, ip=172.20.70.18, mac=00-21-28-0e-94-ce-00-00-00-00-00-00-00-00-00-00-00-2f-ff-ff, net=172.20.70.0/24, mask=255.255.255.0, use=public/1]\r\nPublic Interface 'nxge21' configured from GPnP for use as a public interface.\r\n [name='nxge21', type=1, ip=100.100.100.1, mac=00-21-28-0e-8c-af-00-00-00-00-00-00-00-00-00-00-00-2f-ff-ff, net=100.100.100.0/23, mask=255.255.254.0, use=public/1]\r\nShared memory segment for instance monitoring created\r\nCELL communication is configured to use 0 interface(s):\r\nCELL IP affinity details:\r\n NUMA status: NUMA system w/ 3 process groups\r\n cellaffinity.ora status: cannot find affinity map at '/etc/oracle/cell/network-config/cellaffinity.ora' (see trace file for details)\r\nCELL communication will use 1 IP group(s):\r\n Grp 0: \r\nPicked latch-free SCN scheme 3\r\nUsing LOG_ARCHIVE_DEST_1 parameter default value as /dbtop/grid/dbs/arch\r\nAutotune of undo retention is turned on. \r\nLICENSE_MAX_USERS = 0\r\nSYS auditing is disabled\r\nNOTE: Volume support enabled\r\nNUMA system with 3 nodes detected\r\nStarting up:\r\nOracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production\r\nWith the Real Application Clusters and Automatic Storage Management options.\r\nORACLE_HOME = /dbtop/grid\r\nSystem name: SunOS\r\nNode name: sec33-e\r\nRelease: 5.10\r\nVersion: Generic_142909-17\r\nMachine: sun4u\r\nUsing parameter settings in server-side spfile /dbtop/asm/dbs/spfile+ASM.ora\r\nSystem parameters with non-default values:\r\n large_pool_size = 12M\r\n instance_type = \"asm\"\r\n remote_login_passwordfile= \"EXCLUSIVE\"\r\n asm_diskstring = \"/dev/rdsk/*\"\r\n asm_diskgroups = \"WFREC\"\r\n asm_diskgroups = \"WFDATA\"\r\n asm_power_limit = 7\r\n diagnostic_dest = \"/dbtop/app/oracle\"\r\nCluster communication is configured to use the following interface(s) for this instance\r\n 169.254.121.29\r\ncluster interconnect IPC version:Oracle UDP/IP (generic)\r\nIPC Vendor 1 proto 2\r\nFri Jan 24 05:29:03 2014\r\nPMON started with pid=2, OS id=17520 \r\nFri Jan 24 05:29:04 2014\r\nPSP0 started with pid=3, OS id=17521 \r\nFri Jan 24 05:29:05 2014\r\nVKTM started with pid=4, OS id=17522 at elevated priority\r\nVKTM running at (10)millisec precision with DBRM quantum (100)ms"; var m, res = []; while ((m = rx.exec(str)) !== null) { res.push([m[1], m[2]]); } console.log(res);