Different way to handle --

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11143647 use warnings; while (my $x = <DATA>) { chomp $x; print "\n$x\n"; my $out = ''; while ( $x =~ m/ ([[:punct:]]*) # $1: leading punct marks ( # $2: a "word" consisting of [[:word:]]+ # word (?: (?: '-? | - ) [[:word:]]+ # and ending in pure word characters )* ) ( (?: --+ | [[:punct:]]* ) \ ? ) # $3: trailing punct marks +ending # or multi-dashs # with space (except at end of # line?) /xxg ) { $out .= sprintf "{%s|%s|%s} ", # make whitespace visible map {(my $y = $_ // '') =~ tr/ /_/; $y} $1, $2, $3; } print "$out\n" =~ s/ $//r =~ s/.{65}\K /\n/gr; } __DATA__ "'Uncouth' about sums it up." The word they will use is 'uncouth'. "It's the old story." It's a will-o'-the-wisp--a two-fer--and Bob's-yer-uncle at four o'cloc +k. It's two o'clock--time for a nap. Remember 45's? What about (this)? [Editor's note: blah blah] and so on... A ... and B I said--"What's the expression?"

Outputs (changed to be able to see all output without scrolling):

"'Uncouth' about sums it up." {"'|Uncouth|'_} {|about|_} {|sums|_} {|it|_} {|up|."} The word they will use is 'uncouth'. {|The|_} {|word|_} {|they|_} {|will|_} {|use|_} {|is|_} {'|uncouth|'.} "It's the old story." {"|It's|_} {|the|_} {|old|_} {|story|."} It's a will-o'-the-wisp--a two-fer--and Bob's-yer-uncle at four o'cloc +k. {|It's|_} {|a|_} {|will-o'-the-wisp|--} {|a|_} {|two-fer|--} {|and|_} {|Bob's-yer-uncle|_} {|at|_} {|four|_} {|o'clock|.} It's two o'clock--time for a nap. {|It's|_} {|two|_} {|o'clock|--} {|time|_} {|for|_} {|a|_} {|nap|.} Remember 45's? {|Remember|_} {|45's|?} What about (this)? {|What|_} {|about|_} {(|this|)?} [Editor's note: blah blah] and so on... {[|Editor's|_} {|note|:_} {|blah|_} {|blah|]_} {|and|_} {|so|_} {|on|. +..} A ... and B {|A|_} {|and|_} {|B|} I said--"What's the expression?" {|I|_} {|said|--} {"|What's|_} {|the|_} {|expression|?"}

Did get every thing right?


In reply to Re: Problem with a text-parsing regex by tybalt89
in thread Problem with a text-parsing regex by ibm1620

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.