in reply to Slicing a string on words
Would something like this be simpler?
You might need some code to handle edge cases like 0 for $window_start or $window_size. Note that I used {0,$window_size} so that asking for too big of a window just matches through the last word.$window_size--; my( $windowed_text )= $text_body =~ /^\s*(?:\S+\s+){$window_start}(\S+(?:(\s+\S+){0,$window_size})/;
Note that my technique can also give you the same index information via @- and @+ if you have Perl v5.6 or higher.
- tye (but my friends call me "Tye")
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (tye)Re: Slicing a string on words
by Hofmator (Curate) on Aug 28, 2001 at 21:27 UTC | |
by tye (Sage) on Aug 28, 2001 at 21:31 UTC | |
|
Re: (tye)Re: Slicing a string on words
by dga (Hermit) on Aug 29, 2001 at 22:09 UTC |