Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Exact pattern match inside index()

by toolic (Bishop)
on Oct 15, 2012 at 20:21 UTC ( #999170=note: print w/replies, xml ) Need Help??


in reply to Exact pattern match inside index()

You could use a regex with pos:
use warnings; use strict; my $s = 'CATALOG SCATTER CAT CATHARSIS'; my $k = 'CAT'; if ($s =~ /\b$k\b/g) { print "match started at position ", (pos($s) - length($k)), "\n"; } __END__ match started at position 16

UPDATE: kennethk's @- is much cleaner.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999170]
help
Chatterbox?
[Discipulus]: indeed! new firefox seems poorer: many tab crash, and you open this link in FF?
[Discipulus]: problem scrolling even main page..;=(
[LanX]: holli -> Good Intentions: Wikisyntax for the Monastery
[LanX]: monklinks are automatically converted ...
[LanX]: On another node, I just saw yesterday that the everything engine supports auto-paragraph whithout the need to type <p>
LanX i.e. the newest everything engine

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2017-11-20 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (291 votes). Check out past polls.

    Notices?