Java Regex: Remove Double Quotes from Strings
You can use the replace() method to remove double quotes at the beginning and end. Here is an example code:
String input = "\"Hello World\"";
String output = input.replaceFirst("^\"|\"$", "");
System.out.println(output);
The output is:
Hello World
In this example, the replaceFirst() method is used to replace the first occurrence of double quotes in a string. The regular expression ^\” represents starting with a double quote, and the regular expression \”$ represents ending with a double quote. Using an empty string “” as the replacement content removes the double quotes at the beginning and end.