For the replacement. You need to first get the content value of name field. Then you can remove special characters from the string.
Example code block:
String line = "name=\"xyz =bcd .olm --=myname\""; Pattern pattern = Pattern.compile("name=\"(.*)\""); Matcher matcher = pattern.matcher(line); if (matcher.find()) { String nameString = matcher.group(1); String newNameString = nameString.replaceAll("[^A-Za-z0-9 ]", ""); String result = line.replace(nameString, newNameString); System.out.println(result); }
Result prints as name="xyz bcd olm myname"