[Tutor] ASP parsing

Nicholas Wieland nicholas_wieland@yahoo.it
Fri Feb 21 06:04:01 2003


On 2003.02.19 06:36 Danny Yoo wrote:
> snip >

Ok, here's the code I have now:

import re

f = open ("cdonts.asp", "r")
text = " ".join(f.readlines())
p = re.compile(r'<%.*?%>', re.DOTALL)
asp_part = re.match(p, str(text))

if asp_part:
     result = asp_part.group()
     q = re.compile(r'".*?"', re.DOTALL)
     quote = re.findall(q, result)
     for i in quote:
         print i

else:
     print "No match"

It works wonderfully... thanks to Danny for the suggestion and 
especially for the pointer...
Two more questions:
1) I can't understand why your regex is quoted three times... Is it 
better than mine ?
2) My approach was to stop and write on a file the translated text 
every time the parser encountered a string that needs translation, 
inserting it in the ASP code.
Now I have an array with all the text I need to translate, but how can 
I insert it in the context of the ASP code ? I was thinking about a for 
loop using the re.split() function, but I'm not sure about it...

TIA,
	Nicholas