Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

In my reply above, I wrote

However, also note that if the "random amount of other text" preceding the  'b' in a trigger line may contain any whitespace, then the
    my $pre = qr{ \S+ \s }xms;
regex will have to be changed accordingly.
In the OP, a typical  'b' line was
    '1n5P/1P4PK/1q6 b - - 2 42"]'
In the post to which this is a reply, a typical  'b' line is
    '[FEN "1B6/1Q4bk/R5p1/1pp4p/8/1n5P/1P4PK/1q6 b - - 2 42"]'
with more than one whitespace character before the 'b'. Accordingly, I have altered the $pre regex to
    my $pre  = qr{ \S+ \s \S+ \s }xms;
(This is not what I would consider a "robust" regex, but you will have to provide a regex that best matches your data if you wish an improvement.)

In addition, in the OP a typical  'Weiss' line had leading whitespace; in the most recent post, it has none. Accordingly, I have altered the $post regex to
    my $post = qr{ \s [^\n]+ \n [^\{]* \{ }xms;
(note [^\{]* vice [^\{]+).

I have downloaded your latest data to my file 1148125.dat. With the changes above and your latest data:

c:\@Work\Perl\monks\OldChamp>perl -wMstrict -e "use 5.010; ;; my $t = do { local $/; <>; }; print qq{[[$t]] \n\n}; ;; my $pre = qr{ \S+ \s \S+ \s }xms; my $post = qr{ \s [^\n]+ \n [^\{]* \{ }xms; ;; $t =~ s{ ^ $pre b $post \K Weiss \b } {Schwarz}xmsg; ;; print qq{<<$t>> \n\n}; " 1148125.dat [[.......... [FEN "1B3k2/2R1b3/4p1pp/2r1P1p1/6P1/7P/5PK1/8 w - - 4 34"] {Weiss am Zug} * .......... [FEN "1B6/1Q4bk/R5p1/1pp4p/8/1n5P/1P4PK/1q6 b - - 2 42"] {Weiss am Zug} * ........... [FEN "1Bn4r/1k3q2/1pp1bbp1/1N1p1p1r/Q2Pp3/6PN/PP2PPB1/K1R4R b - - 0 23 +"] {Weiss am Zug} * ........... [FEN "1K6/4kp2/1P4p1/7p/7P/1r3PP1/1p6/1R6 w - - 3 52"] {Weiss am Zug} * ]] <<.......... [FEN "1B3k2/2R1b3/4p1pp/2r1P1p1/6P1/7P/5PK1/8 w - - 4 34"] {Weiss am Zug} * .......... [FEN "1B6/1Q4bk/R5p1/1pp4p/8/1n5P/1P4PK/1q6 b - - 2 42"] {Schwarz am Zug} * ........... [FEN "1Bn4r/1k3q2/1pp1bbp1/1N1p1p1r/Q2Pp3/6PN/PP2PPB1/K1R4R b - - 0 23 +"] {Schwarz am Zug} * ........... [FEN "1K6/4kp2/1P4p1/7p/7P/1r3PP1/1p6/1R6 w - - 3 52"] {Weiss am Zug} * >>
At last,  Weiss has changed.

Give a man a fish:  <%-{-{-{-<

In reply to Re^3: Regex with condition by AnomalousMonk
in thread Regex with condition by OldChamp

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (7)
    As of 2019-08-25 22:32 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found