I have a text file in json, and I want to replace NumberInt(x) with the number x.
In the text file, there are records/data which is in json that has a field workYear: NumberInt(2010) as an example.
I want to replace this into workYear: 2010 by removing NumberInt( and ).
This NumberInt(x) is located anywhere in text file and I want to replace all of it with its number.
I can search all the occurences of this, but I am not sure how to replace it with just the number value.
String json = <json-file-content>
String sPattern = "NumberInt\\([0-9]+\\)";
Pattern pattern = Pattern.compile(sPattern);
Matcher matcher = pattern.matcher(json);
while (matcher.find()) {
String s = matcher.group(0);
int workYear = Integer.parseInt(s.replaceAll("[^0-9]", ""));
System.out.println(workYear);
}
I would like to replace all the NumberInt(x) with just the number value int json String... then I will update the text file (json file).
Thanks!