正则表达式不匹配所有可能性

正则表达式不匹配所有可能性

我在使用正则表达式时遇到了一些麻烦...我正在尝试解析一个 HTML 文件,寻找两个<br>标签之间的某些文本...在这些<br>(文本位于此处)<br>标签之间,总是有 3 种不同类型的文本那里 ...

Type 1)<br>S987 *BREKER BRD AUDIO-10 WX/R RADAR BOX,MAN,AC 24.95 GOOD<br>

类型 1 始终以字母字符开头,后跟 3 个数字,然后是各种不同的字符,如您所见。

Type 2)<br>==== ========== =============== ======= ====================<br>

类型 2 总是一堆“=”符号和空格...

Type 3)<br>Is normal text and may sometimes contain "=" signs<br>

现在,我的问题是这样的...即使有数百行,也只返回类型 1 的第一个实例...另外...我不希望类型 2 或类型 3 匹配...只有类型 1 的位于<br>标签之间...

目前我正在使用以下内容:

/<br>([A-Z]{1}\d{3}.*?)<br>/

这是针对 php 的...

谢谢

丹尼

答案1

<your_enormous_example \
sed -netP -e's/<br>[[:alpha:]][0-9]\{3\}[^<]*<br>/\n&\n/;D;:P' -eP\;D

<br>D163 *ALERT WRK EAR-10          EMERGENCY WEATHER RADIO        BOX,MAN,AC PS          24.95 GOOD<br>
<br>D147 *AMERITRON AWM35           FLAT SWR/WATT METER            BOX,MAN               124.95 GOOD       S/N 013029<br>
<br>D113 *AOR       AR-DV1B         RCVR .10-1300MHZ BLOCKED       BOX,MAN,ANT,PS        959.95 GOOD       S/N 09560012<br>
<br>D152 *ASTRON    SL11A           PS 13V - 9 AMP                 BOX,MAN                69.95 GOOD<br>
<br>D118 *BEARCAT   BCD-396XT       DIGITAL TRUNKING HH SCANNER    BOX,MAN,ACCYS         299.95 GOOD       S/N 359Z48002616<br>
<br>D126 *COMET     RS720           REAR LIP MOUNT NO COAX         MAN,BOX                19.95 GOOD<br>
<br>D300 *CRANE     WITNESS PLUS    AM/FM RADIO WITH MP3           BOX,MAN               132.95 GOOD       S/N 20701418<br>
<br>D110 *DEGEN     DE  15          RCVR MW/SW/FM                  BOX,MAN,BATTS,CASE     31.95 GOOD       S/N FB026781<br>
<br>D142 *DEGEN     DE1126          DIGITAL AM/FM/SW/MP3           BOX,MAN                58.95 GOOD       S/N GC036267<br>
<br>D307 *ETON      FR 600 BLK      AM/FM/WX/SW                    BOX,MAN                55.95 GOOD       SMALL CRACK DISPLAY<br>
<br>D162 *ETON      SATELLIT        AM/FM/SW                       BOX,MAN               159.95 GOOD       S/N 4B00088112S<br>
<br>D166 *ETON      SCORP ORG       EMERGENCY AM/FM/WX ORANGE      BOX,MAN                37.95 GOOD       S/N 100NOR001987<br>
<br>D159 *HEIL      CC1-KM          MIC CABLE KENW  MODL RED       NONE                   28.95 GOOD<br>
<br>D104 *ICOM      MBF1            SUCTION MOUNT                  BOX                    54.95 GOOD<br>
<br>D140 *ICOM      PS126           PS                             BOX,MAN               379.95 GOOD<br>
<br>D146 *ICOM      R  75           RCVR COMM GC DIG 0.3-60MHZ     COUPON ELIGIBLE-BOX   619.95 GOOD       S/N 2203411<br>
<br>D155 *ICOM      SM 50           DESK MIC 7600                  NONE                  239.95 GOOD       S/N 02070171<br>
<br>D149 *SANGEAN   DT-200X         AM/FM POCKET RADIO             BOX,MAN,EARBUDS        37.95 GOOD       S/N 29011218<br>
<br>D145 *SANGEAN   PT- 50          PORT DIG RCVR                  BOX,MAN                49.95 GOOD       S/N 3C018394<br>
<br>D184 *SANGEAN   RCR 8WF         FM/WI-FI CLOCK RADIO           BOX,MAN               139.95 GOOD       S/N 0903000789<br>
<br>D109 *SANGEAN   WR 2WH WHT      AM/FM DIGITAL TABLE WHITE      BOX,MAN,ACCS          104.95 GOOD       S/N 0604000196<br>
<br>D170 *SONY      ICF-SW7600GR    RCVR PORT DIG LW/MW/FM/SW      BOX,MAN,ANT 60        139.95 GOOD       S/N 306100<br>
<br>D143 *VECTRONIC PM30UV B        SWR 30/300W 100-500 BNC        BOX,MAN                62.95 GOOD<br>
<br>D153 *YAESU     FT 277R         HT 440    5W                   BOX,MAN,ANT,CHRGR     109.95 GOOD       S/N 2L500093<br>
<br>D114 *YAESU     FT 277R         HT 440    5W                   BOX,MAN               109.95 GOOD       S/N 21500091<br>
<br>W631 BELL&HOWEL 9 BAND RADIO    FM/MW/SW PORTABLE RADIO        MAN,BOX,EAR BUDS       10.95 GOOD       S/N A9029589<br>
<br>W301 EVEREX     GP41D           PORT. COLOR CAMERA(HITACHI)    BOX,AP4U AC ADAPTOR    49.95 GOOD       S/N 3036899<br>
<br>W920 MFJ         1278           MULTIMODE DATA CONTROLLER      FINAL SALE             51.95 AS IS      NOT TESTED/AS IS<br>
<br>Y004 PACCOMM    TNC 220         DUAL MODEM PACKET CONTROLLER   MANUAL                 44.95 GOOD<br>
<br>U424 TORRESTRON HC-1            CHARGE ADPT. ICOM              MAN.                    3.95 GOOD<br>
<br>B103 _USED BOOK BY AMECO        AMATEUR RADIO THEORY COURSE                           10.95 GOOD       1976 EDITION<br>
<br>B105 _USED BOOK BY ARRL         HANDBOOK 2014                                         29.95 GOOD<br>
<br>B072 _USED BOOK BY DARC         RADIO AMATEURS WORLD ATLAS     1993 EDITION           19.95 GOOD<br>
<br>B277 _USED BOOK BY HEATHKIT     GENERAL LICENSE CONTINUING ED  2 VOLUMES              19.95 GOOD<br>
<br>B113 _USED BOOK BY IBS          PASSPORT 1996                                          9.95 GOOD<br>
<br>B071 _USED BOOK BY IBS          PASSPORT 2003                  NONE                    9.95 GOOD<br>
<br>B169 _USED BOOK BY IOTA         "IOTA DIRECTORY"                                       4.00 GOOD<br>
<br>B171 _USED BOOK BY IOTA         "IOTA DIRECTORY"                                       4.00 GOOD<br>
<br>B084 _USED BOOK BY MCCULLY      POCKET REF VX-7R                                      10.00 GOOD<br>
<br>B078 _USED BOOK BY NATIONAL NC  "INSTR MAN NATIONAL NC-173"                           19.95 GOOD<br>
<br>B014 _USED BOOK BY WRTH         "1995 WRTH"                                            9.95 GOOD<br>
<br>B067 _USED BOOK BY WRTH         "WRTH 1991 EDITION"                                    9.95 GOOD<br>
<br>B065 _USED BOOK BY WRTH         "WRTH 1995 EDITION"                                    9.95 GOOD<br>
<br>B254 _USED BOOK BY WRTH         WRTH 1996                                              6.95 GOOD<br>
<br>B108 _USED BOOK BY WRTH         WRTH- 4 BOOKS 1995,96,97,98                           34.95 GOOD<br>

相关内容