Before asking this question I have Googled for this problem and I have looked through all StackOverflow related questions.
The problem is pretty simple
I have a string “North Atlantic Treaty Organization”
I have a pattern “a.*z”, at moment it would match
north ATLATIC TREATY ORGANIZation
But I need it to match complete words only (orgANIZation for example)
I have tried “\baz\b” and “\Baz\B” as pattern, but I think I don’t quite get it
How should I change my pattern in order to match complete words that string contains (without matching multiple words)
The patterns are generated on the fly, user enteres a*z and my application translates it into pattern that matches parts of complete words in string.
My problem is that I don’t know what user is going to search for. Ideally I would preppend some regexp to user’s expression.
Thank You!
ANIZ in orgANIZation is not a complete word — it’s a part of a word. Your pattern btw is not what you wrote —
a*zwould not match as you describe; you’re probably usinga.*zinstead, which would. So, trya[^ ]*zso it won’t match spaces. If there are other characters besides spaces that you don’t want to match, e.g. some kinds of punctuation, stick them in the[^...]construct as well, of course.