I’m using the following regular expression to find the exact occurrences in infinitives. Flag is global.
(?!to )(?<!\w) (' + word_to_search + ') (?!\w)
To give example of what I’m trying to achieve
- looking for out should not bring : to outlaw
- looking for out could bring : to be out of line
- looking for to should not bring : to etc. just because it matches the first to
I’ve already done these steps, however, to cross out/off should be in the result list too. Is there any way to create an exception without compromising what I have achieved?
Thank you.
I’m still not sure I understand the question. You want to match something that looks like an infinitive verb phrase and contains the whole word
word_to_search? Try this:Remember, when you create a regex in the form of a string literal, you have to escape the backslashes. If you tried to use “\b” to specify a word boundary, it would have been interpreted as a backspace.