|There's more than one way to do things|
Exact pattern match inside index()by jayarkay (Initiate)
|on Oct 15, 2012 at 20:08 UTC||Need Help??|
jayarkay has asked for the
wisdom of the Perl Monks concerning the following question:
I am trying to use the index() function and I want to find the position of a word inside a string, only when it is an exact match. For example:
My string is STRING="CATALOG SCATTER CAT CATHARSIS"
And my search string is KEY=CAT
I want to say something like index($STRING, $KEY) and get the position of CAT, and not CATALOG. How do I accomplish this? The documentation says "The index function searches for one string within another, but without the wildcard-like behavior of a full regular-expression pattern match", which makes me think that it may not be that straight-forward, but my perl skills are limited :). Is it possible to do what I am trying to do?
Hopefully, I was able to articulate my question well. Thanks in advance for your help!