Re: Test string against expression?
Buck Golemon <[email protected]> Mon, 17 Sep 2012 11:04:16 -0700
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <CANDQx1r1ZdKROhJVk8wOgf=8gAuHGQGKuqvjaOBmFibN=RmkDQ@mail.gmail.com> |
--===============3761037133921535511==
Content-Type: multipart/alternative; boundary=f46d043892bd10e30e04c9e99af3
--f46d043892bd10e30e04c9e99af3
Content-Type: text/plain; charset=ISO-8859-1
Cheetah is a superset of python (kindof).
Get your logic working in python, then port it to cheetah.
You want re.match, from the standard python library:
http://docs.python.org/library/re.html#re.RegexObject.match
In your particular example below however, regular expressions are overkill,
just use the string `in` operator:
#if 'string' in $getVar('name')
#set foo = "bar"
#else
#set bar = "foo"
#end if
That's basic python. You should take a couple hours and run through the
official tutorial.
At *least* skim the parts on string processing.
http://docs.python.org/tutorial/
On Mon, Sep 17, 2012 at 10:46 AM, Rick Miller <[email protected]>wrote:
> Hi All,
>
> Please forgive my ignorance for I am a novice in the area of
> templating engines and cheetah. That said, I want to compare a string
> in a placeholder against a regular expression (btw, this is in
> Cobbler...not sure if it makes a real difference or not). The concept
> is as follows:
>
> #if $getVar('name') == '*string*'
> #set foo = "bar"
> #else
> #set bar = "foo"
> #end if
>
> What is the best approach to accomplishing this?
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Cheetahtemplate-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
>
--f46d043892bd10e30e04c9e99af3
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Cheetah is a superset of python (kindof).<div>Get your logic working in pyt=
hon, then port it to cheetah.</div><div>You want re.match, from the standar=
d python library:</div><blockquote style=3D"margin:0 0 0 40px;border:none;p=
adding:0px">
<div><a href=3D"http://docs.python.org/library/re.html#re.RegexObject.match=
">http://docs.python.org/library/re.html#re.RegexObject.match</a></div></bl=
ockquote><div><br></div><div>In your particular example below however, regu=
lar expressions are overkill, just use the string `in` operator:</div>
<div><br></div><div>#if=A0'string' in=A0$getVar('name')</di=
v><div>=A0 =A0#set foo =3D "bar"<br>#else<br>=A0 =A0#set bar =3D =
"foo"<br>#end if</div><div><br></div><div>That's basic python=
. You should take a couple hours and run through the official tutorial.</di=
v>
<div>At *least* skim the parts on string processing.</div><div><a href=3D"h=
ttp://docs.python.org/tutorial/">http://docs.python.org/tutorial/</a>=A0<br=
><br><div class=3D"gmail_quote">On Mon, Sep 17, 2012 at 10:46 AM, Rick Mill=
er <span dir=3D"ltr"><<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Hi All,<br>
<br>
Please forgive my ignorance for I am a novice in the area of<br>
templating engines and cheetah. =A0That said, I want to compare a string<br=
>
in a placeholder against a regular expression (btw, this is in<br>
Cobbler...not sure if it makes a real difference or not). =A0The concept<br=
>
is as follows:<br>
<br>
#if $getVar('name') =3D=3D '*string*'<br>
=A0 =A0#set foo =3D "bar"<br>
#else<br>
=A0 =A0#set bar =3D "foo"<br>
#end if<br>
<br>
What is the best approach to accomplishing this?<br>
<br>
---------------------------------------------------------------------------=
---<br>
Live Security Virtual Conference<br>
Exclusive live event will cover all the ways today's security and<br>
threat landscape has changed and how IT managers can respond. Discussions<b=
r>
will include endpoint security, mobile security and the latest in malware<b=
r>
threats. <a href=3D"http://www.accelacomm.com/jaw/sfrnl04242012/114/5012226=
3/" target=3D"_blank">http://www.accelacomm.com/jaw/sfrnl04242012/114/50122=
263/</a><br>
_______________________________________________<br>
Cheetahtemplate-discuss mailing list<br>
<a href=3D"mailto:[email protected]">Cheetahtem=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-dis=
cuss" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/cheeta=
htemplate-discuss</a><br>
</blockquote></div><br></div>
--f46d043892bd10e30e04c9e99af3--
--===============3761037133921535511==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
--===============3761037133921535511==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
--===============3761037133921535511==--