I have a string on which I try to create a regex mask that will show N
number of words, given an offset. Let's say I have the following string:
"The quick, brown fox jumps over the lazy dog."
I want to show 3 words at the time:
offset 0
: "The quick, brown"
offset 1
: "quick, brown fox"
offset 2
: "brown fox jumps"
offset 3
: "fox jumps over"
offset 4
: "jumps over the"
offset 5
: "over the lazy"
offset 6
: "the lazy dog."
I'm using Python and I've been using the following simple regex to detect 3 words:
>>> import re
>>> s = "The quick, brown fox jumps over the lazy dog."
>>> re.search(r'(\w+\W*){3}', s).group()
'The quick, brown '
But I can't figure out how to have a kind of mask to show the next 3 words and not the beginning ones. I need to keep punctuation.