Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
> I'll update an SSCCE soon.

here we go

(update: please see Re: wiki regex reprocessing replacement (UPDATED^2) for better testcases including wrong markup)

use strict; use warnings; use Data::Dump qw/pp dd/; use Test::More; my $wiki = '_/one *two*/ three_ null _/four *five*/ six_ null _/seven *eight +*/ nine_'; my $expected = '<u><i>one <b>two</b></i> three</u> null <u><i>four <b>five</b></i +> six</u> null <u><i>seven <b>eight</b></i> nine</u>'; my $pre = qr/(^|\s|>)/; my $post = qr/($|\s|<)/; my %h = ( '*' => 'b' , '/' => 'i' , '_' => 'u' , ); sub tf { s{ $pre ([_*/]) (.*?) \2 (?=$post)}{$1<$h{$2}>$3</$h{$2}>}xg +}; $_=$wiki; my $DBG = 1; diag "IN <= '$wiki'\n\n" if $DBG; for my $i (1..3) { tf(); diag "$i: '$_'\n\n" if $DBG; } is($_,$expected," repeated replace works"); done_testing;

# IN <= '_/one *two*/ three_ null _/four *five*/ six_ null _/seven *e +ight*/ nine_' # # 1: '<u>/one *two*/ three</u> null <u>/four *five*/ six</u> null <u> +/seven *eight*/ nine</u>' # # 2: '<u><i>one *two*</i> three</u> null <u><i>four *five*</i> six</u> + null <u><i>seven *eight*</i> nine</u>' # # 3: '<u><i>one <b>two</b></i> three</u> null <u><i>four <b>five</b></ +i> six</u> null <u><i>seven <b>eight</b></i> nine</u>' # ok 1 - repeated replace works 1..1
# IN <= '_/one *two*/ three_ null _/four *five*/ six_  null _/seven *eight*/ nine_'
# 
# 1: '/one *two*/ three null /four *five*/ six  null /seven *eight*/ nine'
# 
# 2: 'one *two* three null four *five* six  null seven *eight* nine'
# 
# 3: 'one two three null four five six  null seven eight nine'
# 
ok 1 -  repeated replace works
1..1

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re: wiki regex reprocessing replacement by LanX
in thread wiki regex reprocessing replacement by LanX

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, 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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (5)
    As of 2020-12-02 07:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How often do you use taint mode?





      Results (35 votes). Check out past polls.

      Notices?