I want to delete the pattern %17\{#MARKERS.*MARKERS#} in a textfile like this:

[FEN "r2qk2r/ppp3pp/2bp1n2/2b1p3/2Q1P3/5N2/PPP2PPP/RNB2RK1 w kq - 0 10 +"] {%17{#MARKERS - N #B(8/8/8/8/8/8/8/8) #S(8/8/8/2DO1DO3/8/8/8/8) #C( +8/8/8/8/8/8/8/8) #F(8/8/8/8/8/8/8/8) MARKERS#}} 10.Nxe5 {%16I} Bxf2+ 11.Rxf2 {%1610} dxe5 12.Nc3 Qe7 13.Be3 a6 14.Rd1 $16 {Minchev Valentin - Stefanov Stefan, * [FEN "N2q1bk1/pp1b1r1p/3p1nn1/P2Pp3/1P2Pp2/5Pp1/4BBPP/2RQNRK1 b - - 0 +21"] {%17{#MARKERS - N LA4(f6:h5) LA4(h5:g3) #B(8/8/8/8/8/8/8/8) #S(8/8/8/8/8/8/8/8) #C(8/8/8/8/8/8/8/8) #F(8/8/8/8/8/8/8/8) MARKERS +#}} 21...Nh5 {! %16I} 22.Kh1 ( 22.Bxa7 Qh4 {%16I} 23.h3 Bxh3 {%16I} 24.gxh3 Qxh3 {%16I} 25.Rf2 gxf2+ {%16I} 26.Kxf2 Nh4 27.Bf1 ( 27.Nc2 Rg7 28.Ke1 Rg2 29.Qd3 Ng3 $19 ) Qh2+ {%16I} 28.Ng2 Rg7 $17 {%16I} ) gxf2 {%16I} ( 22...Qh4 {?} 23.Bg1 ) 23.Rxf2 Ng3+ {! %16I} 24.Kg1 ( 24.hxg3 fxg3 $19 ) Qxa8 25.Bc4 {%17{#MARKERS - N LA4 +(a7:g1) #B(8/8/8/8/8/8/8/8) #S(8/8/8/8/8/8/8/8) #C(8/8/8/8/8/8/8/8 +) #F(8/8/8/8/8/8/8/8) MARKERS#}} a6 {! ('with the idea'Qa7 'diagonals'a7-g1) %1680} 26.Qd3 ( 26.hxg3 fxg3 27.Rb2 Qd8 28.Kf1 ( 28.f4 Rxf4 29.Qd3 Bh6 30.Rcb1 ( 30.Rc3 Qh4 31.Qxg3 Qxg3 32.Rxg3 Rxe4 33.Be2 Bf4 $17 ) b5 31.Bb3 Qc7 32.Nf3 Nh4 ) Bh6 29.Ke2 Qg5 $17 ) Qa7 {%16I} 27.b5 ( 27.Rcc2 {%17{#MARKERS - N LA4(f8:e7) LA4(e7:h4) #B(8/8/8/8/8/8/8/8) #S(8/8/8/8/8/8/8/8) #C(8/8/8/8/8/8/8/8) #F(8/8/8/8/8/8/8/8) MARKERS +#}} Be7 {'with the idea'Bh4} $19 {%16I} ) axb5 {%16I} 28.Bxb5 Nh1 {! 0-1, Piket Jeroen - Kasparov Gary, Tilburg 1989 It %1620} *

I have tried it with this code

#!/usr/bin/perl # Remove extra text from a PGN or Text-file. # Aufruf: perl removeEK4.pl In.txt > Out.txt use strict; use warnings; my $regex = '%17\{#MARKERS.*MARKERS#}'; my $line = do { local $/; <>; }; $line =~ s/\n/ /g; $line =~ s/$regex/ /gi; $line =~ s/ (\d+\. |\[)/\n$1/g; print $line;

What I wanted to get was this:

[FEN "r2qk2r/ppp3pp/2bp1n2/2b1p3/2Q1P3/5N2/PPP2PPP/RNB2RK1 w kq - 0 10 +"] 10.Nxe5 {%16I} Bxf2+ 11.Rxf2 {%1610} dxe5 12.Nc3 Qe7 13.Be3 a6 14.Rd1 +$16 {Minchev Valentin - Stefanov Stefan, * [FEN "N2q1bk1/pp1b1r1p/3p1nn1/P2Pp3/1P2Pp2/5Pp1/4BBPP/2RQNRK1 b - - 0 +21"] 21...Nh5 {! %16I} 22.Kh1 ( 22.Bxa7 Qh4 {%16I} 23.h3 Bxh3 {%16I} 24.gxh +3 Qxh3 {%16I} 25.Rf2 gxf2+ {%16I} 26.Kxf2 Nh4 27.Bf1 ( 27.Nc2 Rg7 28. +Ke1 Rg2 29.Qd3 Ng3 $19 ) Qh2+ {%16I} 28.Ng2 Rg7 $17 {%16I} ) gxf2 {%1 +6I} ( 22...Qh4 {?} 23.Bg1 ) 23.Rxf2 Ng3+ {! %16I} 24.Kg1 ( 24.hxg3 fx +g3 $19 ) Qxa8 25.Bc4 a6 {! ('with the idea'Qa7 'diagonals'a7-g1) %16 +80} 26.Qd3 ( 26.hxg3 fxg3 27.Rb2 Qd8 28.Kf1 ( 28.f4 Rxf4 29.Qd3 Bh6 3 +0.Rcb1 ( 30.Rc3 Qh4 31.Qxg3 Qxg3 32.Rxg3 Rxe4 33.Be2 Bf4 $17 ) b5 31. +Bb3 Qc7 32.Nf3 Nh4 ) Bh6 29.Ke2 Qg5 $17 ) Qa7 {%16I} 27.b5 ( 27.Rcc2 + Be7 {'with the idea'Bh4} $19 {%16I} ) axb5 {%16I} 28.Bxb5 Nh1 {! 0-1 +, Piket Jeroen - Kasparov Gary, Tilburg 1989 It %1620} *

but what I really get is this:

[FEN "r2qk2r/ppp3pp/2bp1n2/2b1p3/2Q1P3/5N2/PPP2PPP/RNB2RK1 w kq - 0 10"]  { } Be7 {'with the idea'Bh4} $19 {%16I} ) axb5 {%16I} 28.Bxb5 Nh1 {! 0-1, Piket Jeroen - Kasparov Gary, Tilburg 1989 It %1620} *

I have asked an online regextester and it showed me, that my regex finds the first occurence of the pattern but then takes everything till the last MARKERS#} What is wrong with my regex?


In reply to How to modify my regex? by OldChamp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.