Yes, johngg,

TIMTOWTDI, and, yes, I think this is definitely of interest++. Having said that, I feel that using zero-width look-around assertions for such a simple case might be a little bit of an overkill. Well, at least for a beginner who obviously doesn't know very much about regexes at this point.

Personally, I'm using look-around assertions only from time to time (sometimes, it is really the best solution), but not often enough to always remember the exact syntax by heart, so that when I feel this is the right solution, I usually have to look it up in Johan Vromans's Perl Pocket Reference (or on the net or somewhere else). For such a simple case, I would rather do most of the job with a simple s/\s+/ /g regex, and add one or two simple regexes to handle leading and trailing spaces if needed. My colleagues having to maintain my code will probably thank me for that and I will be even more delighted when the person having to maintain this code a year from now will be... me.

BTW, Perl 6's regexes have a much cleaner syntax for look-around assertions, so that I would not have the same second thoughts in P6. But that's getting slightly OT, sorry for that.


In reply to Re^2: Deleting intermediate whitespaces, but leaving one behind each word by Laurent_R
in thread Deleting intermediate whitespaces, but leaving one behind each word by Feneden

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.