Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999170]
[marto]: damn
[choroba]: Munich is kind of close from here
[Corion]: marto: Maybe in three years it'll be Berlin again ;)
[marto]: in 3 years I may be able to go :P
[Corion]: choroba: Both teams will ponder on whether/where/how to organize things. The workshop will be mainly in German though
[Corion]: marto: Hehe ;)
[marto]: my out of working hours time is very scarce at the moment
[marto]: unfortunately for you guys I can still access PM during the day :P
[Corion]: marto: Ow, I hope that gets better soonish! But I feel some $work-timecrunch looming at my $work as well
[Corion]: marto: Ah, so you can multiplex work and PM time ;-D

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2017-06-29 08:19 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (655 votes). Check out past polls.