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!