in reply to Re^2: Using pos() inside regexp (no /e)
in thread Using pos() inside regexp

If I'm reading that correctly, you want a newline at the end? If so, the following will do:
# Adds trailing newline s/([^\n]{0,14},|[^\n]{15})(?!\n)/$1\n/g
Compare with tye's:
# Doesn't add trailing newline s/([^\n]{0,14},|[^\n]{15})(?=[^\n])/$1\n/g

Replies are listed 'Best First'.
Re^4: Using pos() inside regexp (fixed)
by tye (Sage) on Oct 08, 2010 at 17:48 UTC

    Did you try your solution? It doesn't add a trailing newline (nor fix the more important problem). Here's my next stab:

    s{( (?:[^\n]{1,15})(?=\n|$) # Line requiring no wrapping | (?:[^\n]{0,14},)(?!\n) # Line that can be wrapped at comma | (?:[^\n]{15})(?!\n) # Line to be wrapped, not at comma )\n? }{$1\n}gx;

    And just two test cases:

    (update) Note there are three ways to write part of that: (?=\n|$) or (?![^\n]) or (?m:$). The last can be written as just $ by putting the m option on the end of the s/// construct. I leave the choice up to you.

    - tye        

      You are my hero :)
      Yes, i've tried my solution, and extra new line at the end is not a big problem.
      But \n in the middle of the initial string is a possible situation, so thanks a large for you attention!