|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I cannot figure this out. I am trying to make a templating program, and I want to make a it process code blocks like this one...
Code:
{iterate name="i" list="list1"}
<tr><td>{list1[i]}</td></tr>
{/iterate}
using this : re.compile("\{iterate name=\"(.*)\" list=\"(.*)\"\}(.*)\{/iterate\}", re.DOTALL) It works fine with just one block, but put two or more in a file and the regex finds from the first {iterate...} to the very last {/iterate}, ignoring any other closing or new iterate tags in between. How can I modify this regex to stop after it reaches the first {/iterate} tag it finds? I am using python 2.2 in cgi and note and am somewhat new to python and pretty new to regex. |
|
#2
|
||||
|
||||
|
One answer is to make the match non-greedy:
"\{iterate name=\"(.*?)\" list=\"(.*?)\"\}(.*?)\{/iterate\}" grimey ![]()
__________________
*** Experimental Python Markup CGI V2 *** |
|
#3
|
|||
|
|||
|
Thank you very much, just what I was looking for. I'll have to read up on greediness/laziness.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Regular Expressions Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|