Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Problem: how to split long words

by jbware (Chaplain)
on Aug 24, 2004 at 15:55 UTC ( [id://385425]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Problem: how to split long words
in thread Problem: how to split long words

I noticed the end '-' thing too. I did add a section to ccn's code that handles that. Its tagged w/ the "# ADDED" comment.

++ btw ccn, took me awhile to wrap my head around this one.

my $brackets = qr(\[[^\]]*\]); # text enclosed in brackets my $char = qr([^\[\]\s]); # not spaces or brackets s{ ( # group to $1 (?: $char # a char (?:$brackets*) # followed by any number of brackets ) {3} # 3 times ) (?!(?:$brackets*)(?:\s|\Z)) # ADDED: eliminates '-' on the end of wo +rds w/ a multiple of 3 chars (?= # looking forward to ensure that [^\[\]]* # we are not inside of a brackets (?: \[ | \z ) ) } {$1-}gx; print;


-jbWare

Replies are listed 'Best First'.
Re^4: Problem: how to split long words
by nikos (Scribe) on Aug 25, 2004 at 07:14 UTC
    Thank you very much! ccn, jbware
    Your solution is great.
    I've made a one-liner from it and it looks like
    $text=~s{((?:([^\[\]\s])(?:(\[[^\]]*\])*)){3})(?!(?:(\[[^\]]*\])*)(?:\s|\Z))(?=[^\[\]]*(?:\[|\z))}{$1-}gx;
    It's so nice! Can be used in some obfuscation code... Thanks again!

Log In?
Username:
Password:

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

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

    No recent polls found