in reply to Problem: how to split long words
$_ = 'ju[color=1]s[/color]t a sam[color=2]p[/color]le'; 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*) # followed by any number of brackets (?= # looking forward to ensure that $char # we have at least one char [^\[\]]* # and we are not inside of a brackets (?: \[ | \z ) ) } {$1-}gx; print;
Update: fixed "last '-'" issue pointed by ikegami
P.S. Concerning '[2345678901234567890' I suggest that is not valid input.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem: how to split long words
by ikegami (Patriarch) on Aug 24, 2004 at 15:45 UTC | |
by jbware (Chaplain) on Aug 24, 2004 at 15:55 UTC | |
by nikos (Scribe) on Aug 25, 2004 at 07:14 UTC | |
by ccn (Vicar) on Aug 24, 2004 at 19:42 UTC | |
by nikos (Scribe) on Sep 01, 2004 at 14:09 UTC | |
|
Re^2: Problem: how to split long words
by nikos (Scribe) on Sep 01, 2004 at 14:01 UTC |