Hi All,
I built a Python com server to solve regular expressions for use in a VBA
application. Here's the code:
import pythoncom
import re
import string
class reObj:
_public_methods_ = ["re"]
_reg_progid_ = "Python.reObj"
_reg_clsid_ = pythoncom.CreateGuid()
def __init__ (self):
pass
def re(self, pattern, str):
result=''
matchGroup=re.search(pattern,str)
while matchGroup<>None:
(start,end)=matchGroup.span()
result = result + ", " + str[start:end]
str=str.replace(str[start:end],'',1)
matchGroup=re.search(pattern,str)
return result[2:]
def listem(self, list):
for item in list:
print item, r.re(p,item)
if __name__ == '__main__':
import win32com.server.register
win32com.server.register.UseCommandLine(reObj)
The last few lines register the com server, so all that is necessary is to
execute the code.
Calling from VBA is:
Dim re As Object
Set reObj = CreateObject("Python.reObj")
Result = reObj(pattern, string)
_
I got the basic idea from something I found on the web.
Cheers, Gary
__________________________________
"Even for practical purposes theory generally turns out the most important
thing in the end." Oliver Wendell Holmes.
_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32