|
From: <bc...@wo...> - 2002-02-06 10:47:16
|
[Guy Gascoigne-Piggford]
>I guess that I didn't explain my self very clearly, though I think that you
>did answer my question. I've written a java module that extends jython, I
>want that java module to use regular expressions in the same way that jython
>does. As you say
No, that is not quite what I said. I meant that sre only works in a
jython environment.
>that would involve using sre and I can't do that from a
>java module :-(
A java class like this below can imported from jython and can make use
of all the other jython modules, classes and functions.
import org.python.core.*;
public class y {
public static void test() {
// import re
PyObject re = __builtin__.__import__("re");
// res = re.match(r"(source filename|Name of).*\?(?i)",
"nAME OF ?")
PyObject res = re.invoke("match",
Py.java2py("(source filename|Name of).*\\?(?i)"),
Py.java2py("nAME OF ?"));
// print res.group(1)
System.out.println(res.invoke("group", Py.newInteger(1)));
}
}
Jython 2.1+ on java1.4.0-beta3 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> import y
>>> y.test()
nAME OF
regards,
finn
|