|
I seem to have hit upon a corner case - or it's so easy, no one has ever asked! I have a list of desired words I'd like to match in a block of text. However, I only want to match the first occurrence of each of these. If my block of text reads:
I'd like to match: I'm learning how to narrow it down as I try to understand the groupings... This: gives me "ghost" occurrences:
Wrapping my desired words in brackets as a set (group?) like this:
which is so far the best (narrowest) I can get. I would have expected that:
without the /g global flag would give me the first occurrence of "my" OR "desired" OR "words", but it stops at the first find, "glass". So to restate the question, I'm trying to find the first instance of each of these words (first of door, and first of window, and first of glass) wrapped by (?:[\s]|^) and (?=[\s]|$), in a block of text. Many thanks! |