Discussion:
[Templates] question about variable within match
Eric Goldhagen
2002-06-05 20:10:13 UTC
Permalink
I am having a bit of a hard time figuring this one out.

[% matches = fullstory.match('(\w+ word \w+)') %]


This works fine. But, how do I get a variable such as $s_word or
$form.query in the middle of the pattern?

[% matches = fullstory.match('(\w+ $s_word \w+)') %]

and

[% matches = fullstory.match('(\w+ \"$s_word\" \w+)') %]


don't work....

I am rather new to this stuff, so any help or pointers would be appreciated.

--Eric
------------
ABC No Rio http://www.abcnorio.org
The Interactivist Network http://www.interactivist.net
Autonomedia http://www.autonomedia.org
Nomad Media Lab http://www.nomadlab.com
Randal L. Schwartz
2002-06-05 20:19:21 UTC
Permalink
Eric> [% matches = fullstory.match('(\w+ \"$s_word\" \w+)') %]

[% matches = fullstory.match("(\\w+ $s_word \\w+)") %]

(I *think* -- I don't like those whitespaces in there... so you
might need to remove them.)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<***@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Eric Goldhagen
2002-06-05 20:43:49 UTC
Permalink
Randal,

thanks, but it still does not work for me.

I tried
[% matches = fullstory.match("(\\w+ $s_word \\w+)") %]

and

[% matches = fullstory.match("(\\w+$s_word\\w+)") %]

any other ideas?


And while I am here, I have one more template-toolkit question.

I am running a site using slashcode. I can't figure out how to set
EVAL_PERL so that I can use [% PERL %] in my templates. I tried to
follow the docs, but it seems that slash interfaces to TT oddly.


--Eric
Post by Randal L. Schwartz
Eric> [% matches = fullstory.match('(\w+ \"$s_word\" \w+)') %]
[% matches = fullstory.match("(\\w+ $s_word \\w+)") %]
(I *think* -- I don't like those whitespaces in there... so you
might need to remove them.)
--
Randal L. Schwartz
------------
ABC No Rio http://www.abcnorio.org
The Interactivist Network http://www.interactivist.net
Autonomedia http://www.autonomedia.org
Nomad Media Lab http://www.nomadlab.com
Randal L. Schwartz
2002-06-05 21:08:37 UTC
Permalink
Eric> Randal,
Eric> thanks, but it still does not work for me.

Eric> I tried
Eric> [% matches = fullstory.match("(\\w+ $s_word \\w+)") %]

Eric> and

Eric> [% matches = fullstory.match("(\\w+$s_word\\w+)") %]

Eric> any other ideas?

$ tpage
[%
fullstory = "kermit the frog";
s_word = "the";
matches = fullstory.match("(\\w+ $s_word \\w+)");
FOREACH m = matches;
"one match is <"; m; ">\n";
END;
%]
^D
one match is <kermit the frog>
$

Looks good to me. You have only one paren set, so you get
back only one match.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<***@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Eric Goldhagen
2002-06-05 21:28:48 UTC
Permalink
--============_-1188809197==_ma============
Content-Type: text/plain; charset="us-ascii" ; format="flowed"
Post by Randal L. Schwartz
Eric> Randal,
Eric> thanks, but it still does not work for me.
Eric> I tried
Eric> [% matches = fullstory.match("(\\w+ $s_word \\w+)") %]
Eric> and
Eric> [% matches = fullstory.match("(\\w+$s_word\\w+)") %]
Eric> any other ideas?
$ tpage
[%
fullstory = "kermit the frog";
s_word = "the";
matches = fullstory.match("(\\w+ $s_word \\w+)");
FOREACH m = matches;
"one match is <"; m; ">\n";
END;
%]
^D
one match is <kermit the frog>
$
Looks good to me. You have only one paren set, so you get
back only one match.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
OK

Something must be wrong on my system.

If I do this via tpage I get the right result.

But if I put the code into a template and hit the page, I just get
one match is

and nothing else.

I will move the code over to another machine and try again.

Thanks for the help.

--Eric

------------
ABC No Rio http://www.abcnorio.org
The Interactivist Network http://www.interactivist.net
Autonomedia http://www.autonomedia.org
Nomad Media Lab http://www.nomadlab.com
--============_-1188809197==_ma============
Content-Type: text/enriched; charset="us-ascii"




At 2:08 PM -0700 6/5/02, Randal L. Schwartz wrote:

<excerpt>>>>>> "Eric" == Eric Goldhagen <<***@nomadlab.com> writes:


Eric> Randal,

Eric> thanks, but it still does not work for me.


Eric> I tried

Eric> [% matches = fullstory.match("(\\w+ $s_word \\w+)") %]


Eric> and


Eric> [% matches = fullstory.match("(\\w+$s_word\\w+)") %]


Eric> any other ideas?


$ tpage

[%

fullstory = "kermit the frog";

s_word = "the";

matches = fullstory.match("(\\w+ $s_word \\w+)");

FOREACH m = matches;

"one match is <<"; m; ">\n";

END;

%]

^D

one match is <<kermit the frog>

$


Looks good to me. You have only one paren set, so you get

back only one match.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095

<<***@stonehenge.com> <<URL:http://www.stonehenge.com/merlyn/>

Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.

See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!


</excerpt>


OK


Something must be wrong on my system.


If I do this via tpage I get the right result.


But if I put the code into a template and hit the page, I just get

<color><param>2222,2222,2222</param> one match is


</color>and nothing else.


I will move the code over to another machine and try again.


Thanks for the help.


--Eric

------------

ABC No Rio http://www.abcnorio.org

The Interactivist Network http://www.interactivist.net

Autonomedia http://www.autonomedia.org

Nomad Media Lab http://www.nomadlab.com

--============_-1188809197==_ma============--
Eric Goldhagen
2002-06-05 22:51:23 UTC
Permalink
Post by Randal L. Schwartz
Eric> Randal,
Eric> thanks, but it still does not work for me.
Eric> I tried
Eric> [% matches = fullstory.match("(\\w+ $s_word \\w+)") %]
Eric> and
Eric> [% matches = fullstory.match("(\\w+$s_word\\w+)") %]
Eric> any other ideas?
$ tpage
[%
fullstory = "kermit the frog";
s_word = "the";
matches = fullstory.match("(\\w+ $s_word \\w+)");
FOREACH m = matches;
"one match is <"; m; ">\n";
END;
%]
^D
one match is <kermit the frog>
$
Looks good to me. You have only one paren set, so you get
back only one match.
A quick re-install of TT and all is well.

THANKS for the help.

--Eric

------------
ABC No Rio http://www.abcnorio.org
The Interactivist Network http://www.interactivist.net
Autonomedia http://www.autonomedia.org
Nomad Media Lab http://www.nomadlab.com

Continue reading on narkive:
Loading...