Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Using pos() inside regexp (no /e)

by ikegami (Patriarch)
on Oct 08, 2010 at 15:32 UTC ( [id://864212]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://864212]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-23 16:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found