Yes, it seems that twhyman wants something like the "word match" option of some text editors (found also in Wordpad).
Laszlo's code is even more "lot of code", but it can be put in a function and reused in a simple way.
Coding this would be impractical in AHK, as the meaning of "word" is somewhat fuzzy. Some text editors allows to define a set of alphanumeric chars defining such a word, allowing double-click selection and find option.
Depending on context, one would want to allow _ - ' or even é ç or @ in the words... Or course, Chris can also add a way to define the char set of word.
As Chris points out, the use case is quite rare, it may not worth to put it in AHK. Regular expressions would be more powerful, but as they would be used only by power users, perhaps the current solution (an external DLL) is probably practical enough (except you have to distribute the DLL with your scripts...).
If twhyman wants to play with PCREAHK, I would suggest to try the "[^[:alnum:]]yourword[^[:alnum:]]" expression.
OK, I finally made the real test, as it allows me to test this PCRE stuff. The expression wasn't so simplistic, as we need to match the search string at the beginning or the end of the line:
text = cmd.exec and MyCMD.exe are not cmd.exe
searchText = cmd.exe
pattern := "(?:[^[:alnum:]]|^)" . searchText . "(?:[^[:alnum:]]|$)"
res := RE_Match(text, 0, pattern, 1, result)
If (res == 0)
{
MsgBox %pattern% Not found
}
Else If (res < 0)
{
MsgBox Error (%res%): %result%
}
Else
{
StringSplit, x, result, %A_Space%
StringMid found, text, x1 + 1, x2
MsgBox Result of RE_Match: %result%, found: %found%
}
RE wonderful and powerful :-)
I use the RE_Match function given in the MATCH.AHK script.
For those wondering and not willing to read the whole
specification, the (?:foo|bar) syntax allows to search for either foo or bar without capturing the string. Above, 'foo' is clear (any non-alphanumeric char), 'bar' is either the start (^) or end ($) of the string.