I am having a little trouble with a regular expression ... I am trying to parse an HTML file looking for certain text between two <br> tags ... between these <br>(text goes here)<br> tags there are always 3 different types of text that will be there ...

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

Type 1 will ALWAYS start with an ALPHABETICAL character followed by EXACTLY 3 digits and then followed by all sorts of different characters as you can see ..

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

Type 2 are ALWAYS a bunch of "=" signs and spaces ...

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

Now, my problem is this ... only the first instance of Type 1 are returned even though there are hundreds of those lines ... also ... I do not want Type 2's or Type 3's matched ... only Type 1's that are in between the <br> tags ...

Currently I am using the following:


This is for php ...

Thank You


  • Are you using grep? Can you provide a snippet of your sample file? – Ron Dec 6 '15 at 16:18
  • 1
    Your requirements conflict. Type one alphabetic matches "is normal text" in type 3 – Jeff Schaller Dec 6 '15 at 16:41
  • What do you want from the line <br>s001<br>s002<br> ? When you want to use grep or sed, you should convert your file first into lines with two <br>'s. When everything is given as one long line, you get one match. – Walter A Dec 6 '15 at 16:49
  • 1
    Why are people voting to close this?  Has the problem “gone away”?  Has somebody identified a trivial typo in the OP’s usage?  … …  @JeffSchaller: What are you talking about?  While “normal text” is terribly vague and open-ended, the closest I can come to making ^letter-digit-digit-digit look like “normal text” is “A100-year-old-man walked into a bar …”, and that’s obviously contrived (it works only because I left out the space that belongs between the “A” and the “100”).  OK, or “T101 is an early version of the Terminator series.” – Scott Dec 6 '15 at 23:24
  • @Danny: (1) How are you doing this search?  grep? vi? sed?  With what options?  (2) Does the line that was matched by any chance have a question mark immediately before the second <br>? – Scott Dec 6 '15 at 23:25
<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>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>
  • mikeserv: Thank you for that ... I will vote for it if I can make it work in php which by my futile attempts I cannot seem to get it right ... here is my attempt to convert it to php: ([[:alpha:]][0-9]{3}[^<]*) ... which obviously is wrong as it still only returns the first match only and not all the matches like yours does ... ;( ... – Danny Dec 7 '15 at 15:30
  • @Danny - just use a pipeline. – mikeserv Dec 7 '15 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.