in reply to (tye)Re: Slicing a string on words
in thread Slicing a string on words
Very nice solution, tye!!
There's a small typo in the regex (a surplus parenthesis), so here goes the code again, corrected
What I wanted to add is that Perl handles the boundary cases very nicely, so no extra handling required for $window_start = 0 or $window_size = 0. This means$window_size--; my( $windowed_text )= $text_body =~ /^\s*(?:\S+\s+){$window_start}(\S+(?:\s+\S+){0,$window_size})/;
which is exactly what we need for the code to work fine.$_ = q/01234/; /^..{0}/; # matches '0' /^..{0,0}/; # matches '0' /^..{0,-1}/; # doesn't match at all
-- Hofmator
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re2: Slicing a string on words
by tye (Sage) on Aug 28, 2001 at 21:31 UTC |