@priyanka9 You should check whether the paragraph becomes empty after replacing placeholder and remove it in such case. Please try using the following code:
@Override
public int replacing(ReplacingArgs args) throws Exception {
String arg = args.getMatch().group();
arg= removeBrackets(arg);
//assuming whatever the args are there in list are not satisfying condition and trying to remove them
if(list.contains(arg)){
Paragraph para = (Paragraph) args.getMatchNode().getParentNode();
// Get paragraph text
String paraText = para.toString(SaveFormat.TEXT).trim();
paraText = paraText.replace(args.getMatch().group(), "");
// Remove the paragraph with the matched text.
if(paraText.equals("")) {
para.remove();
return ReplaceAction.SKIP;
}
else {
args.setReplacement("");
return ReplaceAction.REPLACE;
}
} else {
args.setReplacement("ReplacemntValue is:"+arg);
return ReplaceAction.REPLACE;
}
}