Reputation: 7
nodenName = VAS_DEL_SDC_LB1_ONM_DEL_10.200.98.74;
private String extractNodeName(String nodeName) {
String output = "";
Matcher match = Pattern.compile("[0-9]+").matcher(nodeName);
while (match.find()) {
output.split(match.group());
}
return output;
}
can anybody help me out for extracting only VAS_DEL_SDC_LB1_ONM_DEL
, the above i tried its not working
Upvotes: 0
Views: 53
Reputation:
Try this:
private static String extractNodeName(String nodeName) {
return nodeName.replaceAll("[\\d_.]{2,}", "");
}
Upvotes: 0
Reputation: 174696
Just match all the chars upto the first _
which exist before a digit.
String output = "";
Matcher match = Pattern.compile(".*?(?=_[0-9])").matcher(nodeName);
while(match.find())
{
output = m.group();
}
return output;
Upvotes: 1
Reputation: 1212
private String extractNodeName(String nodeName) {
String output = "";
Matcher match = Pattern.compile("\\w+(?<!\\d|_)").matcher(nodeName);
while (match.find()) {
output = match.group();
}
return output;
}
Result:
VAS_DEL_SDC_LB1_ONM_DEL
Upvotes: 1