jayarkay has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Exact pattern match inside index()
by kennethk (Abbot) on Oct 15, 2012 at 20:27 UTC | |
|
Re: Exact pattern match inside index()
by toolic (Bishop) on Oct 15, 2012 at 20:21 UTC | |
|
Re: Exact pattern match inside index()
by Anonymous Monk on Oct 15, 2012 at 20:20 UTC | |
|
Re: Exact pattern match inside index()
by jayarkay (Initiate) on Oct 17, 2012 at 15:48 UTC |