Use a regex: you can set it up so that it's a more sophisticated match than just "this text string":
Pattern (Java Platform SE 7 )[
^]
For example, the match string might be:
\$field2(?=\s|$)
Which requires the "field2" to be followed by either a space or the end of the string - so "$field25" no longer matches but the "$field2" does.