I am python programmer and always played regular expressions in python but recently I have been asked to use java flavor regular expression, does mean I have to write application in java. So just checking is there a way to use java regex in python? Thanks
1 Answer
Below java program need to be run first
import py4j.GatewayServer;
public class AdditionApplication {
public int addition(int first, int second) {
return first + second;
}
public static void main(String[] args) {
AdditionApplication app = new AdditionApplication();
// app is now the gateway.entry_point
GatewayServer server = new GatewayServer(app);
server.start();
}
}
Below is the way to access java addition method in python
from py4j.java_gateway import JavaGateway
gateway = JavaGateway()
gateway.entry_point.addition(10, 10)
2 Comments
Per, py4j.org, the port #s used are 25332-25334, but per iana.org/assignments/service-names-port-numbers/…, those port # are unassigned.
DataNoob
They may not be but default ports. These ports can be changed py4j.org/py4j_java_gateway.html#module-py4j.java_gateway
(?:(?<!.?[-:0-9\/] ?)the optional . and space does not work in python