I have the following regular expression to find word in text and highlight them
Using the word surface for testing purposes.
/((?<=[\W])surface?(?![\w]))|((?<![\w])surface?(?=[\W]))/iu
It matches all occurences in the following text.
surface-CoP-20-70-0000-04-02_Pre-Run_Tool_Verification_Programming_and_surface_Tare surface_revC.pdf
But if i change the first occurence of surface to contain a upper case letter, it only matches the first occurence.
Surface-CoP-20-70-0000-04-02_Pre-Run_Tool_Verification_Programming_and_surface_Tare surface_revC.pdf
Or if i put an upper case letter in some of the other occurences it matches that.
Surface-CoP-20-70-0000-04-02_Pre-Run_Tool_Verification_Programming_and_Surface_Tare surface_revC.pdf
I have no idea what you’re trying to achieve there, but possibly your problem is that
\wwill include_(and\Wwill exclude it).Maybe try this:
Or this:
Otherwise, please provide more details on what exactly you do/don’t want to match.
Update: given this information:
In that case, I suspect you want:
(since just
\bwould exclude a match containing “…and_surface_Tare…” so we add the alternation with_to include that.)