Re: Find number of matches using Match
Summer <crazysummer2004-/[email protected]> Tue, 22 May 2012 11:03:51 -0700 (PDT)
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Message-ID | <[email protected]> |
Initially I did try this and it didn' work. After trying out the following example:
[% text = 'no, i do not believe we could not go forward to the sea. I know. no'; %]
So, to get the count:
[% text.match('no', 1).size %]
That should match 5x, yet it shows 1 when I do .size
thanks
--- On Mon, 5/21/12, Ronald J Kimball <rkimball-jkI2qz8QNLsmlAP/[email protected]> wrote:
From: Ronald J Kimball <rkimball-jkI2qz8QNLsmlAP/[email protected]>
Subject: Re: [Templates] Find number of matches using Match
To: "Summer" <crazysummer2004-/[email protected]>
Cc: "[email protected]" <[email protected]>
Date: Monday, May 21, 2012, 7:48 PM
On Mon, May 21, 2012 at 9:44 PM, Summer <crazysummer2004-/[email protected]> wrote:
Hey,
I am using the "match" method and I am looking for a regex in a string. For the sake of argument, lets say we are looking for "no" in the following.
testString =""no, i do not believe we could not go forward to the sea. I know. no;
so,
valHolder = testString.match("(?i:no)");
valHolder.size -> always gives me 1. Yet I am expecting 4 matches.
Is there a way I can know the count of the matches?
http://template-toolkit.org/docs/manual/VMethods.html#method_match
To perform a global search to match the pattern as many times as it appears in the source string, provide a true value for the "global"
argument following the pattern.
[% text = 'bandanna'; text.match('an+', 1).join(', ) # an, ann
%]
So, to get the count:
[% text.match('no', 1).size %]
Ronald
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates