[Zope] Using regexes in DTML expressions

Duncan Booth duncan@rcp.co.uk
Wed, 10 Nov 1999 09:46:37 +0000


> I'd like to be able to use a regex from the Python re module in a <dtml-if>
> tag expression, e.g.
> 
> 	<dtml-if "_.re.search('(([Ps|Sc|S|C][i|y])|Sigh)Comp?', company_name)">
> 		Pickled pink.
> 	</dtml-if>
> 
> What is the easiest way to do something like this?
> 
Edit DT_Util.py, changing line 200 from:
	import string, math, whrandom
to
	import string, math, whrandom,re

And after line 215:
	d['whrandom']=whrandom
insert:
	d['re']=re

(Line numbers refer to Zope 2.0.1, but the lines should be easily 
identifiable in other versions.)

I cannot see any good reason why this change couldn't be included 
in the release so I will submit it to the collector.

-- 
Duncan Booth                                             duncan@dales.rmplc.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
http://dales.rmplc.co.uk/Duncan