Removing First and Last Double Quotes

java, regex, string

Solution

If the `"` characters are always going to be the first and last ones, you don't need a regex. Just use `substring`:

x = x.substring(1, x.length() - 1)

Problem

I have set of `String`s where the first and last characters are double quotes. Below is an example. ``` String x = "‘Gravity’ tops the box office for 3rd week | New York Post" ``` Some other strings will contain double quotes in the middle of the text, so I can't use `String.replaceAll()`. I just need to remove the first and last double quotes. How can I do this?

Original source