You can do this with a String#replaceAll
method:
str = str.replaceAll("-(nic|a)\\b", "");
Regex -(nic|adm)
matches a hyphen followed by nic
or adm
.
\\b
is for word boundary to make sure we don’t match unwanted text like abc
.
You can add more suffixes in this group that you want to be removed.
solved Java regex: Multiple delimiters preceded by “-”