PERL lookahead and lookbehinds?

So, it’s my understanding that with PERL(according to this text i’m reading) that with look aheads if you’re looking for back injury, you’ll only match “back” if followed by “injury” and conversely with look behinds you’ll only match “injury” if preceded by “back”

but all that seems unnecessary. Why not just search for the exact phrase “back injury” and be done with it?

Perhaps something related to optimization of the compiled code that is more efficient if it’s matching on fewer characters . . .
:man_shrugging:

I don’t know anything about PERL, but in regex (in which I’m quite a novice) I usually find negative lookaheads and lookbehinds more useful. I want to find the “back” instances that are not “back injury” or the “injury” instances that are not “back injury.”

Still, if you want to perform an operation on just certain words out of a phrase, then a positive lookahead or lookbehind could be useful. If you’re animating text in a videogame or something and you want to animate the word “darkness” any time it appears in the phrase “darkness my old friend” but not other times, perhaps a programmer could use a positive lookahead to automatically apply that. In that case, grabbing the whole phrase might not be useful.

To the extent my post is not generalizable to PERL, please ignore :face_with_tongue: