Using regexpal.com to practice my regular expressions. I decided to start simply and ran into a problem.
Say you want to find all 3 letter words.
\\s\\w{
(?<=\s)\w{3}(?=\s)
Overlapping spaces.
Use 0 width assertions instead.When you use \s\w{3}\s
on " abc acd " the regex engine consumes abc
so the only thing left is acd
which your regex will not match.So use lookaround
to just assert and not consume.
EDIT:
\b\w{3}\b
Can also be used.
\b==>assert position at a word boundary (^\w|\w$|\W\w|\w\W)
or
(?:^|(?<=\s))\w{3}(?=\s|$)
This will find your 3 letter word even if it is at start or in middle or at end.