3

http://gskinner.com/RegExr/下面的正则表达式工作但不是在 PHP

(?>AB/HDR)(?:[^])*?(?=AB/HDR|RUN DATE|\z)

在 PHP 中是这样说的:

preg_match() [function.preg-match]: Unknown modifier '(' in E:\xampp\htdocs.....

没有太多的想法尝试以下变化,但没有结果

%(?>AB/HDR)(?:[^])*?(?=AB/HDR|RUN DATE|\z)% 
> result : Compilation failed: missing terminating ] for character class at offset 41

%(?>AB/HDR)(?:\[^])*?(?=AB/HDR|RUN DATE|\z)%
> result : 0 match which is incorrect

任何帮助,将不胜感激 !!!

测试数据

RUN DATE: 15FEB12                        F E D E R A L    E X P R E S S     C O R P O R A T I O N             PAGE:    1
RUN TIME: 09:36                               INTERNATIONAL DETAIL MANIFEST                             REPORT: FEVIP093-R1
SEQUENCE: DN,ST,BT,BA,MB,BD,DV,RT,AWB         OUTBOUND REQUEST BY ROUTE                                   



AB/HDR : 4876  6218  1850  ORIG: SYD     DEST: DAC     ORIGIN CNTRY: AU   EXPORT CNTRY: AU   SHIP DATE: 14FEB12
    CONSIGNEE ACCT : 000000000   PHONE : +88 02 8834304        SHIPPER ACCT : 141639668   PHONE : 0299978166
       COMPANY: EASY FLY EXPRESS LTD                              COMPANY: INTERNATIONAL AIR PARTS
       NAME:    ADYET                                             NAME:    GREG FULLER
       ADDRESS: HOUSE NO.4, 5TH FLOOR, ROAD NO.20                 ADDRESS: 5A JUBILEE AVENUE
       ADDRESS: UTTARA, SECTOR-3                                  ADDRESS:
       CITY:    DHAKA                                             CITY:    WARRIEWOOD
       ST/PV:      CNTRY: BD   POSTAL: 1230                       ST/PV:      CNTRY: AU   POSTAL: 2102
       BROKER:                    PHONE:                     CITY:                    CNTRY:      CUSTOMS ID NBR:
    SVC: 0101 BILL-T/C: S BILL-D/T: S   TTL PKGS:     1   TTL WGT:       0.5 K   CURR: USD   CUSTOMS VALUE:        90.00
MAWB:                DESC: AIRCRAFT PARTS, 1 X FILTER

AB/HDR : 4926  0503  9651  ORIG: SYM     DEST: DAC     ORIGIN CNTRY: CN   EXPORT CNTRY: CN   SHIP DATE: 14FEB12           ECI
    CONSIGNEE ACCT : 000000000   PHONE : 880-27701506-9        SHIPPER ACCT : 354519100   PHONE : 26501338-8004
       COMPANY: HOP LUN BANGLADESH                                COMPANY: FINELINE(4403137628)
       NAME:    MR. EMRAN                                         NAME:    MISS WU
       ADDRESS: BLDG NO. 3 (4 STORIED BLDG)                       ADDRESS: 3F BLDG D,  HUICHAO INDUSTRIAL PAR
       ADDRESS: DHAKA EXPORT PROCESSING ZONE                      ADDRESS: SECOND GUSHU ROAD XIXIANG TOWN,
       CITY:    GANAKBARI SAVAR DHAK                              CITY:    BAOAN DIST SHENZHEN
       ST/PV:      CNTRY: BD   POSTAL: 1349                       ST/PV:      CNTRY: CN   POSTAL: 518102
       BROKER:                    PHONE:                     CITY:                    CNTRY:      CUSTOMS ID NBR:
    SVC: 0101 BILL-T/C: O BILL-D/T: C   TTL PKGS:     2   TTL WGT:       7.7 K   CURR: USD   CUSTOMS VALUE:       346.50
MAWB:                DESC: PRICE TICKET L(4821100000)NO BRAND

   CRN:  492605039662


RUN DATE: 15FEB12                        F E D E R A L    E X P R E S S     C O R P O R A T I O N             PAGE:   11
RUN TIME: 09:36                               INTERNATIONAL DETAIL MANIFEST                             REPORT: FEVIP093-R1
SEQUENCE: DN,ST,BT,BA,MB,BD,DV,RT,AWB         OUTBOUND REQUEST BY ROUTE  
4

1 回答 1

1

首先,这是不允许的

[^]

我已将其替换为.. 其次,您需要模式分隔符:

#(?>AB/HDR)(?:.)*?(?=AB/HDR|RUN DATE|\z)#

忘记dot matches all修饰符:

#(?>AB/HDR)(?:.)*?(?=AB/HDR|RUN DATE|\Z)#s
于 2012-06-03T08:29:35.803 回答