Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Split string using regex on \n or max line length (updated)

by flowdy (Scribe)
on Feb 10, 2017 at 09:11 UTC ( [id://1181641]=note: print w/replies, xml ) Need Help??


in reply to Re: Split string using regex on \n or max line length (updated x3)
in thread Split string using regex on \n or max line length

Update: The following modification to the regex eliminates the need for the s/\s+$// for @lines; above (works because \s includes newline):

I still plead for keeping the \W, best with non-greedifier i.e. \W?, so a final punctuation or hyphen is captured even though the limit is exceeded by one.

Replies are listed 'Best First'.
Re^3: Split string using regex on \n or max line length
by haukex (Archbishop) on Feb 10, 2017 at 13:25 UTC

    Hi flowdy,

    You're right that my second regex didn't operate like the OP's, but if you write /(.{1,$len}\W?)/gm, then that may split in the middle of a word, like your suggestion and unlike the OP's regex. I've updated my node.

    Thanks,
    -- Hauke D

      Hi haukex,

      Yes, you are right. Then again, required \W will not match at the end of the line. So, (?:\W|$) is closer to an ideal solution, which however is rather hypothetical until a proper set of positive and negative test cases is provided.

Log In?
Username:
Password:

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

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

    No recent polls found