I have python code as below. I want to convert this code in Java but I am not getting replacement of match.groupdict()
in Java. I have applied two different regex for each matchRegex(expr, data)
method call in examples below but there may be more regex for every call also. Here is my code:
Python code:
import re
def matchRegex(expr, data):
match = re.compile(expr).match(data)
stmt = match.groupdict()
print("matchRegex() Output = ",stmt)
matchRegex(r'R(?P<rcount>[0-9]*)X?(?P<xdelta>[+\-]?\d*\.?\d*)?Y?(?P<ydelta>[+\-]?\d*\.?\d*)?', "R0004X015Y32")
matchRegex(r'(?P<deprecated>(G54)|(G55))?D(?P<d>\d+)\*', "D10*")
Python Output:
matchRegex() Output = {'rcount': '0004', 'xdelta': '015', 'ydelta': '32'}
matchRegex() Output = {'deprecated': None, 'd': '10'}
My Java Effort :
public Map<String, String> matchRegex(Pattern expr, String data) {
Matcher match = expr.matcher(data);
if (match == null) {
return new HashMap<String, String>();
}else {
/*
Dont know how to implement replacement of "stmt = match.groupdict()"
*/
}