⚠️ NOTE: If you have any questions regarding the content presented below, feel free to post them here. I will be happy to help anyway I can! Regex is a big passion of mine and I look forward to hearing from you. 😁
Positive and negative look arounds are zero width assertions. This means they affect the outcome of the match but are not included in the results. (Like word boundaries and anchors).
- happy(?=\ cat) =~ Matches
happy so long as cat precedes it.
happy(?!\ cat) =~ matches anything after happy but not happy cat.
Positive Look Behind (Must be fixed width)
(?<=happy\ )cat =~ Matches
cat\ when happy comes before it.
Negative Look Behind (Must be fixed width)
(?<!happy\ )cat =~ Will match any
cat so long as it is not happy cat.