tags:

views:

47

answers:

1

thecompletestring must match complete
thecompletelystring must not match complete
theuncompletestring must not match complete
theuncompletelystring must not match complete

I tried word boundaries, but they don't work in URLs.

I have a word list in an array, one word, one item.

How to match a word if it isn't inside an other word?

+4  A: 

This cannot be done with regexp. To successfully distinguish between those cases, you need to write something that understands the English language. That will obviously not be easy to do properly.

To get pretty close, you could use a dictionary of words and see if the string can be split to words in that dictionary with the word you're looking for as one of the words. This will not account for typos or misunderstandings or two words accidentally being considered as one. You would need something that truly speaks a human language for that.

Matti Virkkunen