final String ids = "(\\d+(?:,\\d+)*)";
final Collection<OsmPrimitive> refs = new TreeSet<>(); // error message can contain several times the same way
Matcher m;
m = Pattern.compile(".*Node (\\d+) is still used by relations " + ids + ".*").matcher(msg);
if (m.matches()) {
OsmPrimitive n = new Node(Long.parseLong(m.group(1)));
for (String s : m.group(2).split(",")) {
refs.add(new Relation(Long.parseLong(s)));
}
return Pair.create(n, refs);
}
m = Pattern.compile(".*Node (\\d+) is still used by ways " + ids + ".*").matcher(msg);
if (m.matches()) {
OsmPrimitive n = new Node(Long.parseLong(m.group(1)));
for (String s : m.group(2).split(",")) {
refs.add(new Way(Long.parseLong(s)));
}
return Pair.create(n, refs);
}
m = Pattern.compile(".*The relation (\\d+) is used in relations? " + ids + ".*").matcher(msg);
if (m.matches()) {
OsmPrimitive n = new Relation(Long.parseLong(m.group(1)));
for (String s : m.group(2).split(",")) {
refs.add(new Relation(Long.parseLong(s)));
}
return Pair.create(n, refs);
}
m = Pattern.compile(".*Way (\\d+) is still used by relations " + ids + ".*").matcher(msg);
if (m.matches()) {
OsmPrimitive n = new Way(Long.parseLong(m.group(1)));
for (String s : m.group(2).split(",")) {
refs.add(new Relation(Long.parseLong(s)));
}
return Pair.create(n, refs);
}
m = Pattern.compile(".*Way (\\d+) requires the nodes with id in " + ids + ".*").matcher(msg); // ... ", which either do not exist, or are not visible"
if (m.matches()) {
OsmPrimitive n = new Way(Long.parseLong(m.group(1)));
for (String s : m.group(2).split(",")) {
refs.add(new Node(Long.parseLong(s)));
}
return Pair.create(n, refs);
}