I have something akin to <Foobar Name='Hello There'/>
and need to change the single quotation marks to double quotation marks. I tried :s/\'.*\'/\"\0\"
but it ended up producing <Foobar Name="'Hello There'"/>
. Replacing the \0
with \1
only produced a blank string inside the double quotes - is there some special syntax I'm missing that I need to make only the found string ("Hello There") inside the quotation marks assign to \1
?
To remove double quotes just from the beginning and end of the String, we can use a more specific regular expression: String result = input. replaceAll("^\"|\"$", ""); After executing this example, occurrences of double quotes at the beginning or at end of the String will be replaced by empty strings.
press q and q for recording into q register (we use "q" as shortcut to remember "quotes"). press a then press ' again to surround the word with quotes.
Use the String. replace() method to replace single with double quotes, e.g. const replaced = str. replace(/'/g, " ); . The replace method will return a new string where all occurrences of single quotes are replaced with double quotes.
There's also surround.vim, if you're looking to do this fairly often. You'd use cs'"
to change surrounding quotes.
You need to use groupings:
:s/\'\(.*\)\'/\"\1\"
This way argument 1 (ie, \1) will correspond to whatever is delimited by \( and \).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With